]> Cypherpunks repositories - gostls13.git/commit
encoding/gob: optimize decoding of slice
authorkorzhao <korzhao95@gmail.com>
Fri, 3 Sep 2021 07:55:16 +0000 (15:55 +0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 7 Sep 2021 21:39:06 +0000 (21:39 +0000)
commitdcf3545774a8b2bc639f8da14dec2526b8ca9caf
tree40ee01ab5ecab8c225a8cfb33ab77675e08ca4ec
parent80783558b06741beaf41dbd198013fe3a13c9ad2
encoding/gob: optimize decoding of slice

In CL 345572, we used the reflect.Value.SetLen method to avoid
extra memory allocation for reflect.Value.Slice.
This also applies to function decodeSlice

name                   old time/op    new time/op    delta
DecodeStringsSlice-12    96.5µs ±12%    63.0µs ± 8%  -34.68%  (p=0.000 n=9+10)

name                   old alloc/op   new alloc/op   delta
DecodeStringsSlice-12    89.3kB ± 0%    65.3kB ± 0%  -26.89%  (p=0.000 n=10+10)

name                   old allocs/op  new allocs/op  delta
DecodeStringsSlice-12     3.18k ± 0%     2.18k ± 0%  -31.47%  (p=0.000 n=10+10)

Change-Id: Ifdb43716cc90a265962dec022704a5571f447fd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/347533
Reviewed-by: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Rob Pike <r@golang.org>
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
TryBot-Result: Go Bot <gobot@golang.org>
src/encoding/gob/decode.go
src/encoding/gob/timing_test.go