]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: don't allocate to build strings of length 1
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 5 Mar 2017 00:55:03 +0000 (16:55 -0800)
committerKeith Randall <khr@golang.org>
Thu, 1 Mar 2018 17:38:06 +0000 (17:38 +0000)
commit9372e3f5ef6c9653d29cbba2dc06bdcad2b3724c
tree5e6ccf2e6cc1e95698d73881ec6682f1d3830349
parentaa9c1a8f8038e88da6d7cbfdc56e34ff914b7b04
runtime: don't allocate to build strings of length 1

Use staticbytes instead.
Instrumenting make.bash shows approx 0.5%
of all slicebytetostrings have a buffer of length 1.

name                     old time/op  new time/op  delta
SliceByteToString/1-8    14.1ns ± 1%   4.1ns ± 1%  -71.13%  (p=0.000 n=17+20)
SliceByteToString/2-8    15.5ns ± 2%  15.5ns ± 1%     ~     (p=0.061 n=20+18)
SliceByteToString/4-8    14.9ns ± 1%  15.0ns ± 2%   +1.25%  (p=0.000 n=20+20)
SliceByteToString/8-8    17.1ns ± 1%  17.5ns ± 1%   +2.16%  (p=0.000 n=19+19)
SliceByteToString/16-8   23.6ns ± 1%  23.9ns ± 1%   +1.41%  (p=0.000 n=20+18)
SliceByteToString/32-8   26.0ns ± 1%  25.8ns ± 0%   -1.05%  (p=0.000 n=19+16)
SliceByteToString/64-8   30.0ns ± 0%  30.2ns ± 0%   +0.56%  (p=0.000 n=16+18)
SliceByteToString/128-8  38.9ns ± 0%  39.0ns ± 0%   +0.23%  (p=0.019 n=19+15)

Fixes #24172

Change-Id: I3dfa14eefbf9fb4387114e20c9cb40e186abe962
Reviewed-on: https://go-review.googlesource.com/97717
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/string.go