go/src
Daniel Martí 30d3ebe367 encoding/json: remove alloc when encoding short byte slices
If the encoded bytes fit in the bootstrap array encodeState.scratch, use
that instead of allocating a new byte slice.

Also tweaked the Encoding vs Encoder heuristic to use the length of the
encoded bytes, not the length of the input bytes. Encoding is used for
allocations of up to 1024 bytes, as we measured 2048 to be the point
where it no longer provides a noticeable advantage.

Also added some benchmarks. Only the first case changes in behavior.

name                 old time/op    new time/op    delta
MarshalBytes/32-4       420ns ± 1%     383ns ± 1%   -8.69%  (p=0.002 n=6+6)
MarshalBytes/256-4      913ns ± 1%     915ns ± 0%     ~     (p=0.580 n=5+6)
MarshalBytes/4096-4    7.72µs ± 0%    7.74µs ± 0%     ~     (p=0.340 n=5+6)

name                 old alloc/op   new alloc/op   delta
MarshalBytes/32-4        112B ± 0%       64B ± 0%  -42.86%  (p=0.002 n=6+6)
MarshalBytes/256-4       736B ± 0%      736B ± 0%     ~     (all equal)
MarshalBytes/4096-4    7.30kB ± 0%    7.30kB ± 0%     ~     (all equal)

name                 old allocs/op  new allocs/op  delta
MarshalBytes/32-4        2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.002 n=6+6)
MarshalBytes/256-4       2.00 ± 0%      2.00 ± 0%     ~     (all equal)
MarshalBytes/4096-4      2.00 ± 0%      2.00 ± 0%     ~     (all equal)

Updates #5683.

Change-Id: I5fa55c27bd7728338d770ae7c0756885ba9a5724
Reviewed-on: https://go-review.googlesource.com/122462
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-21 09:05:51 +00:00
..
archive archive/tar: remore redundant parens in type expressions 2018-08-21 01:47:17 +00:00
bufio bufio: make Reader naming consistent 2018-08-20 21:51:48 +00:00
builtin
bytes
cmd cmd/compile/internal/gc: unexport Deferproc and Newproc 2018-08-21 08:12:06 +00:00
compress
container container/heap: clarify that Remove returns the removed element 2018-08-20 18:05:11 +00:00
context
crypto all: use internal/cpu feature variables directly 2018-08-20 14:47:07 +00:00
database/sql database/sql: fix driverStmt.Close() comment typo 2018-08-03 03:58:03 +00:00
debug debug/pe: support windows/arm 2018-08-20 18:12:47 +00:00
encoding encoding/json: remove alloc when encoding short byte slices 2018-08-21 09:05:51 +00:00
errors
expvar
flag
fmt strconv: clarify "g" and "G" precision in the docs 2018-08-01 00:57:00 +00:00
go go/doc: compile regexps lazily 2018-08-21 02:51:10 +00:00
hash hash/crc64: lazily initialize slice8Tables 2018-08-21 04:50:21 +00:00
html html: lazily populate Unescape tables 2018-07-31 22:10:54 +00:00
image
index/suffixarray
internal internal/poll: Avoid evaluating condition for an unreachable branch 2018-08-20 21:50:00 +00:00
io
log
math math,net: omit explicit true tag expr in switch 2018-08-20 22:15:59 +00:00
mime
net net/http: add an example of creating a custom FileSystem 2018-08-21 04:55:04 +00:00
os os: handle TMPDIR in TempDir on Plan 9 2018-08-17 23:12:06 +00:00
path path: present the correct error message in TestMatch 2018-07-29 19:18:48 +00:00
plugin
reflect
regexp
runtime runtime: document all possible values for GOOS and GOARCH 2018-08-20 19:14:00 +00:00
sort
strconv strconv: clarify "g" and "G" precision in the docs 2018-08-01 00:57:00 +00:00
strings strings: revise ToUpperSpecial and ToLowerSpecial wording 2018-08-21 04:38:58 +00:00
sync
syscall syscall: add S_IRWXG and S_IRWXO to FreeBSD types 2018-08-21 02:18:19 +00:00
testing testing: exit with error if testing.Short is called before flag.Parse 2018-08-20 21:51:11 +00:00
text text/scanner: don't allow Float exponents with no mantissa 2018-08-20 17:01:34 +00:00
time time: use secondsPerMinute instead of 60 2018-08-21 04:38:18 +00:00
unicode
unsafe
vendor/golang_org/x vendor: update golang.org/x/net/http2/hpack 2018-08-01 20:05:31 +00:00
Make.dist
all.bash
all.bat
all.rc
androidtest.bash
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
cmp.bash
iostest.bash
make.bash cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00
make.bat cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00
make.rc cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00
naclmake.bash
nacltest.bash
race.bash
race.bat
run.bash cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00
run.bat cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00
run.rc cmd/go: add $GOFLAGS environment variable 2018-08-01 00:35:21 +00:00