• Phil Pearl's avatar
    encoding/json: improve performance of Compact · 22d37707
    Phil Pearl authored
    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/+/200864Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    22d37707
bench_test.go 8.59 KB