]> Cypherpunks repositories - gostls13.git/commit
encoding/json: improve performance of Compact
authorPhil Pearl <philip.j.r.pearl@gmail.com>
Sun, 13 Oct 2019 12:01:58 +0000 (13:01 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Sun, 27 Oct 2019 16:02:29 +0000 (16:02 +0000)
commit22d377077c01ced185f5f8d27f608e8c6dcb473c
tree6e2a7c6470f2991ee2a54dded0dcb165bbf8217a
parent31bfab4ac621e81100d7fc3bc8cf483c5d2d2fef
encoding/json: improve performance of Compact

This change improves performance of Compact by using a sync.Pool to allow re-use
of a scanner. This also has the side-effect of removing an allocation for each
field that implements Marshaler when marshalling JSON.

name               old time/op    new time/op    delta
EncodeMarshaler-8     118ns ± 2%     104ns ± 1%  -12.21%  (p=0.001 n=7+7)

name               old alloc/op   new alloc/op   delta
EncodeMarshaler-8      100B ± 0%       36B ± 0%  -64.00%  (p=0.000 n=8+8)

name               old allocs/op  new allocs/op  delta
EncodeMarshaler-8      3.00 ± 0%      2.00 ± 0%  -33.33%  (p=0.000 n=8+8)

Change-Id: Ic70c61a0a6354823da5220f5aad04b94c054f233
Reviewed-on: https://go-review.googlesource.com/c/go/+/200864
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/encoding/json/bench_test.go
src/encoding/json/indent.go
src/encoding/json/scanner.go