-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: []byte conversion to string causes unnecessary alloc #31506
Comments
Minimal repro:
In these cases, we could use slicebytetostringtmp and avoid the allocation. However, detecting when that's safe is rather tricky. In particular, we have to make sure that as long as the converted |
If nothing in the function has synchronization, then it is already unsafe according to the Go memory model for any external code to mutate the |
That's true, but we don't currently have any way to track internal code that might mutate the []byte while the string value is valid. For example:
Even knowing that |
Dup of #2205, no? |
Dup. Correct. I thought an issue existed. Couldn't locate it. |
What version of Go are you using (
go version
)?What did you do?
The following code in our repo incurs an additional alloc when type converting []byte to string --
https://go.googlesource.com/protobuf/+/d3f8f2d4122f4b739c70822f3aae4f82bf28cac9/internal/encoding/json/string.go#68
What did you expect to see?
I was hoping that our case would fall under the improvements mentioned in https://twitter.com/davidcrawshaw/status/1069634054448996354
What did you see instead?
pprof view showing allocation --
The text was updated successfully, but these errors were encountered: