3fb3ca083c
The preallocated memory size is comparable to bytes.Buffer bootstraping array length (bytes.Buffer was used before rewrite to strings.Builder). Without preallocation, encodeWord does more than one allocation for almost any possible input. The regression happens because bytes.Buffer did a 80-bytes allocation at the beginning of encodeWord while strings.Builder did several smaller allocations (started with cap=0). Comparison with reported regression: name old time/op new time/op delta QEncodeWord-4 781ns ± 1% 593ns ± 1% -24.08% (p=0.008 n=5+5) name old alloc/op new alloc/op delta QEncodeWord-4 152B ± 0% 80B ± 0% -47.37% (p=0.008 n=5+5) name old allocs/op new allocs/op delta QEncodeWord-4 5.00 ± 0% 2.00 ± 0% -60.00% (p=0.008 n=5+5) Comparison with buffer solution (like before strings.Builder, but without sync pool for buffer re-using): name old time/op new time/op delta QEncodeWord-4 595ns ± 1% 593ns ± 1% ~ (p=0.460 n=5+5) name old alloc/op new alloc/op delta QEncodeWord-4 160B ± 0% 80B ± 0% -50.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta QEncodeWord-4 2.00 ± 0% 2.00 ± 0% ~ (all equal) We avoid allocation in buf.String(), as expected. Fixes #25379 Change-Id: I19763f0e593a27390c1a549b86ce6507b489046b Reviewed-on: https://go-review.googlesource.com/113235 Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README.md | ||
robots.txt |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.