Conversation
julienschmidt
left a comment
There was a problem hiding this comment.
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: