-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: len() of a local string variable performs better than that of a const or a global #28417
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
Comments
You're measuring the overhead of the loop more than you are measuring the actual cost of
|
15-20% faster is one way of looking at it. But you are measuring difference at a scale of 0.1ns. At that scale, even CPU heat can make an impact. From the generated assembly, there is no difference. I am curious to know if this arose in a real world usecase. Otherwise we will just be trying to understand benchmarking here since the code is the same in all cases. |
I'm going to close this issue, I don't think there is anything actionable here. |
Change https://golang.org/cl/145097 mentions this issue: |
After rewriting my benchmark in accordance to Dave Cheney's recommendations, the effect is gone:
@randall77 Sorry for bothering. Happy that something good did come out of this. |
Unlike normal load+op opcodes, the load+compare opcode does not clobber its non-load argument. Allow the load+compare merge to happen even if the non-load argument is used elsewhere. Noticed when investigating issue #28417. Change-Id: Ibc48d1f2e06ae76034c59f453815d263e8ec7288 Reviewed-on: https://go-review.googlesource.com/c/145097 Reviewed-by: Ainar Garipov <gugl.zadolbal@gmail.com> Reviewed-by: Ben Shi <powerman1st@163.com>
Playground: https://play.golang.org/p/34va1HU2FJ7.
Results:
len(local string variable)
is consistently 15-20% faster on my machine. While global vs local[]byte
have the same performance.The text was updated successfully, but these errors were encountered: