You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at the Unlock method in mutex.go and I noticed something about line #110:
if (new+mutexLocked)&mutexLocked == 0 {
It can be simplified to:
if new&mutexLocked != 0 {
This does not change the functionality of Unlock in any way, other than to speed it up slightly.
Benefit
A quick and dirty test on my machine showed about a 5% run time improvement when doing a Lock/Unlock in a tight loop.
Before: 58.8-59.1 ns
After: 55.6-56.0 ns
Note: I did this in Jan 2016. I discussed it with Dmitry and he recommended submitting it. Then I misplaced it and didn't notice it till now. Sorry for the delay!
The text was updated successfully, but these errors were encountered:
@johnrs you should use a benchmark with https://github.com/rsc/benchstat, that will give more useful results as to whether this change speeds up the function or not.
Also, I think you should open a CL instead of an issue for this. This issue is pretty much just a manual patch submission.
josharian
changed the title
sync.mutex.Unlock: Slight speedup
sync: speed up Mutex.Unlock
Oct 31, 2016
Proposal
I was looking at the Unlock method in mutex.go and I noticed something about line #110:
It can be simplified to:
This does not change the functionality of Unlock in any way, other than to speed it up slightly.
Benefit
A quick and dirty test on my machine showed about a 5% run time improvement when doing a Lock/Unlock in a tight loop.
Before: 58.8-59.1 ns
After: 55.6-56.0 ns
Note: I did this in Jan 2016. I discussed it with Dmitry and he recommended submitting it. Then I misplaced it and didn't notice it till now. Sorry for the delay!
The text was updated successfully, but these errors were encountered: