-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: unnecessary runtime.growslice with provable capacity #66692
Comments
A fix for this should hopefully take #66691 into account such that the following avoids both if cap(dst)-len(dst) < 1+8 {
dst = slices.Grow(dst, 1+8)
}
dst = append(dst, flag)
dst = binary.BigEndian.AppendUint64(dst, src) (Obviously, |
With lots of massaging this works: package main
import "encoding/binary"
var src uint64
var dst []byte
func main() {
if uint(len(dst)+8) > uint(cap(dst)) {
return
}
dst = binary.BigEndian.AppendUint64(dst, src)
} This works because I see at least two things here:
|
CC @golang/compiler. |
Change https://go.dev/cl/599096 mentions this issue: |
Go version
go1.22
Output of
go env
in your module/workspace:What did you do?
Compile the following:
What did you see happen?
I see the following in the assembly:
What did you expect to see?
No call to
runtime.growslice
.This particular example seems silly, but the capacity check already happens elsewhere in code beforehand so there is no possible way that
growslice
would be necessary once we get toAppendUint64
.The text was updated successfully, but these errors were encountered: