]> Cypherpunks repositories - gostls13.git/commit
encoding/gob: avoid a pointer to wireType in typeInfo
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 25 Mar 2023 11:48:41 +0000 (11:48 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 29 Mar 2023 22:57:25 +0000 (22:57 +0000)
commit4d296bcbc25acb14ef603c6824113758d74b4a31
treea4582dd77e03be0b3ec850f32c60dcfe8b17aa38
parent6a51c000def084b820756f066397fd2505e75e25
encoding/gob: avoid a pointer to wireType in typeInfo

wireType itself is just a struct with seven pointer fields,
so an indirection doesn't feel necessary to noticeably reduce the amount
of memory that typeInfo takes for each Go type registered in gob.

The indirection does add a small amount of overhead though,
particularly one extra allocation when registering a type,
which is done a number of times as part of init.

For consistency, also update wireTypeUserInfo to not use a pointer.

Measuring via one of the end-to-end benchmarks and benchinit:

goos: linux
goarch: amd64
pkg: encoding/gob
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│     old     │                new                 │
│   sec/op    │   sec/op     vs base               │
EndToEndPipe-16   736.8n ± 5%   733.9n ± 5%       ~ (p=0.971 n=10)
EncodingGob       177.6µ ± 0%   173.6µ ± 0%  -2.27% (p=0.000 n=10)
geomean           11.44µ        11.29µ       -1.34%

│     old      │                  new                  │
│     B/op     │     B/op      vs base                 │
EndToEndPipe-16   1.766Ki ± 0%   1.766Ki ± 0%       ~ (p=1.000 n=10) ¹
EncodingGob       38.47Ki ± 0%   38.27Ki ± 0%  -0.50% (p=0.000 n=10)
geomean           8.241Ki        8.220Ki       -0.25%
¹ all samples are equal

│    old     │                 new                 │
│ allocs/op  │ allocs/op   vs base                 │
EndToEndPipe-16   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
EncodingGob       652.0 ± 0%   642.0 ± 0%  -1.53% (p=0.000 n=10)
geomean           36.11        35.83       -0.77%
¹ all samples are equal

Change-Id: I528080b7d990ed595683f155a1ae25dcd26394b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/479398
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/encoding/gob/type.go