]> Cypherpunks.ru repositories - gostls13.git/commit
encoding/json: use append for Compact and Indent
authorJoe Tsai <joetsai@digital-static.net>
Mon, 20 Feb 2023 01:11:46 +0000 (17:11 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 24 Feb 2023 19:00:14 +0000 (19:00 +0000)
commit21ff6704bc8efa72abe191263aae938f3c867480
treeab214d4d8d78c74d0941fe3cf0f848495cf242b3
parente7c7f3326335649d6fcae8cba297808fc60ed388
encoding/json: use append for Compact and Indent

This is part of the effort to reduce direct reliance on bytes.Buffer
so that we can use a buffer with better pooling characteristics.

Avoid direct use of bytes.Buffer in Compact and Indent and
instead modify the logic to rely only on append.
This avoids reliance on the bytes.Buffer.Truncate method,
which makes switching to a custom buffer implementation easier.

Performance:

name                old time/op    new time/op    delta
EncodeMarshaler    25.5ns ± 8%    25.7ns ± 9%   ~     (p=0.724 n=10+10)

name                old alloc/op   new alloc/op   delta
EncodeMarshaler     4.00B ± 0%     4.00B ± 0%   ~     (all equal)

name                old allocs/op  new allocs/op  delta
EncodeMarshaler      1.00 ± 0%      1.00 ± 0%   ~     (all equal)

Updates #27735

Change-Id: I8cded03fab7651d43b5a238ee721f3472530868e
Reviewed-on: https://go-review.googlesource.com/c/go/+/469555
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/encoding/json/encode.go
src/encoding/json/indent.go
src/encoding/json/stream.go