]> Cypherpunks repositories - gostls13.git/commit
reflect: make Value an opaque struct
authorRuss Cox <rsc@golang.org>
Thu, 17 Nov 2011 00:18:25 +0000 (19:18 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Nov 2011 00:18:25 +0000 (19:18 -0500)
commita479a455489bc3600c004367f16c4d452705d2c9
tree3bd135e9b88f115d5ab2dc0948f2800427c1ed00
parent4d27f64863ab8518f4ac9f20539bd20c16e77433
reflect: make Value an opaque struct

Making Value opaque means we can drop the interface kludges
in favor of a significantly simpler and faster representation.
v.Kind() will be a prime candidate for inlining too.

On a Thinkpad X201s using -benchtime 10:

benchmark                           old ns/op    new ns/op    delta
json.BenchmarkCodeEncoder           284391780    157415960  -44.65%
json.BenchmarkCodeMarshal           286979140    158992020  -44.60%
json.BenchmarkCodeDecoder           717175800    388288220  -45.86%
json.BenchmarkCodeUnmarshal         734470500    404548520  -44.92%
json.BenchmarkCodeUnmarshalReuse    707172280    385258720  -45.52%
json.BenchmarkSkipValue              24630036     18557062  -24.66%

benchmark                            old MB/s     new MB/s  speedup
json.BenchmarkCodeEncoder                6.82        12.33    1.81x
json.BenchmarkCodeMarshal                6.76        12.20    1.80x
json.BenchmarkCodeDecoder                2.71         5.00    1.85x
json.BenchmarkCodeUnmarshal              2.64         4.80    1.82x
json.BenchmarkCodeUnmarshalReuse         2.74         5.04    1.84x
json.BenchmarkSkipValue                 77.92       103.42    1.33x

I cannot explain why BenchmarkSkipValue gets faster.
Maybe it is one of those code alignment things.

R=iant, r, gri, r
CC=golang-dev
https://golang.org/cl/5373101
src/pkg/reflect/all_test.go
src/pkg/reflect/type.go
src/pkg/reflect/value.go