]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: rewrite empty makeslice to zerobase pointer
authorJorropo <jorropo.pgm@gmail.com>
Wed, 30 Nov 2022 08:45:29 +0000 (09:45 +0100)
committerKeith Randall <khr@golang.org>
Fri, 20 Jan 2023 04:57:35 +0000 (04:57 +0000)
commitfc814056aae191f61f46bef5be6e29ee3dc09b89
tree93c75e8fcf10a4e3d7c4b7116ea7b4bfd71a55e6
parent57236fe9f72c7dae447f07899e9b5b3bcd06f2af
cmd/compile: rewrite empty makeslice to zerobase pointer

make\(\[\][a-zA-Z0-9]+, 0\) is seen 52 times in the go source.
And at least 391 times on internet:
https://grep.app/search?q=make%5C%28%5C%5B%5C%5D%5Ba-zA-Z0-9%5D%2B%2C%200%5C%29&regexp=true
This used to compile to calling runtime.makeslice.
However we can copy what we do for []T{}, just use a zerobase pointer.

On my machine this is 10x faster (from 3ns to 0.3ns).
Note that an empty loop also runs in 0.3ns,
so this really is free when you count superscallar execution.

Change-Id: I1cfe7e69f5a7a4dabbc71912ce6a4f8a2d4a7f3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/454036
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Jakub Ciolek <jakub@ciolek.dev>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/_gen/rulegen.go
src/cmd/compile/internal/ssa/rewritegeneric.go
test/codegen/slices.go