]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: support more length types for slice extension optimization
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Sun, 16 Jun 2019 18:15:53 +0000 (01:15 +0700)
committerKeith Randall <khr@golang.org>
Tue, 17 Sep 2019 17:18:17 +0000 (17:18 +0000)
commitec4e8517cd17aaa2c4224815444e7d28c81ec673
tree224ba47e28e75c563f30cb8dd246c096b969ef59
parent07ad84009865b15d68cba036610d04c66bd3f5e8
cmd/compile: support more length types for slice extension optimization

golang.org/cl/109517 optimized the compiler to avoid the allocation for make in
append(x, make([]T, y)...). This was only implemented for the case that y has type int.

This change extends the optimization to trigger for all integer types where the value
is known at compile time to fit into an int.

name             old time/op    new time/op    delta
ExtendInt-12        106ns ± 4%     106ns ± 0%      ~     (p=0.351 n=10+6)
ExtendUint64-12    1.03µs ± 5%    0.10µs ± 4%   -90.01%  (p=0.000 n=9+10)

name             old alloc/op   new alloc/op   delta
ExtendInt-12        0.00B          0.00B           ~     (all equal)
ExtendUint64-12    13.6kB ± 0%     0.0kB       -100.00%  (p=0.000 n=10+10)

name             old allocs/op  new allocs/op  delta
ExtendInt-12         0.00           0.00           ~     (all equal)
ExtendUint64-12      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Updates #29785

Change-Id: Ief7760097c285abd591712da98c5b02bc3961fcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/182559
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/walk.go
test/codegen/slices.go
test/fixedbugs/issue4085b.go