]> Cypherpunks repositories - gostls13.git/commit
syscall: optimize SlicePtrFromStrings
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 2 Mar 2019 19:14:46 +0000 (11:14 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 2 Mar 2019 20:13:13 +0000 (20:13 +0000)
commit06c86e0fc3eec6635fce31b8cd6b988087a8f872
tree6108c028f5c9d5afaa55e285190c9f8617e5e324
parentbeadf433c37498dafc6748cc510eeab2636b5be3
syscall: optimize SlicePtrFromStrings

Instead of allocating a byte slice for every string,
calculated the required size and create
a single slice big enough to hold all of them.
As an added benefit, any error encountered
will now be returned before allocations occur.

os/exec package benchmarks:

name        old time/op    new time/op    delta
ExecEcho-8    2.14ms ± 1%    2.14ms ± 3%     ~     (p=0.842 n=10+9)

name        old alloc/op   new alloc/op   delta
ExecEcho-8    6.35kB ± 0%    6.18kB ± 0%   -2.65%  (p=0.000 n=10+10)

name        old allocs/op  new allocs/op  delta
ExecEcho-8      69.0 ± 0%      36.0 ± 0%  -47.83%  (p=0.000 n=10+10)

Change-Id: I84118d8473037d873f73903d4e4f6ed14f531ce7
Reviewed-on: https://go-review.googlesource.com/c/164961
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/syscall/exec_unix.go