-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
faster shiftNRuneBytes #305
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the switch
have an impact in the (reliably) measurable range? I'd personally prefer it for its slightly better readability.
We're speaking about sub-ns differences anyway.
I also agree that the previous version is more readable. And I found that the previous benchmark was not reliable, since it was tested on my laptop. A more precise benchmark for this change, the new implementation is
Maybe it is worth to do that? it's your call :) |
Your change consists of two changes: using if/else instead of the switch and using assignments instead of assembling a new array. How does the following perform? switch n {
case 0:
return rb
case 1:
res[0], res[1], res[2] = rb[1], rb[2], rb[3]
case 2:
res[0], res[1] = rb[2], rb[3]
case 3:
res[0] = rb[3]
}
return |
According to the benchmark, looks like the performance improvement comes from both change the
benchstat
|
The new implementation is 1.1x faster than the previous version. Since the shiftNRuneBytes is a Hot Path in lookup function, a small improvement would be meaningful.
A simple benchmark for this change:
benchstat:
Furthermore, the new implementation instructions size reduce to 88(the previous implementation is 143).
Go assembly output: