accessory icon indicating copy to clipboard operation
accessory copied to clipboard

perf: unlock without defer

Open trim21 opened this issue 3 years ago • 4 comments

defer is kind of expensive in this simple variable assignment case

trim21 avatar Oct 20 '22 23:10 trim21

Thank you @trim21 for your comment!

I think you're right, so I'm considering to fix locking without defer.

masaushi avatar Oct 26 '22 04:10 masaushi

any news about this issue?

trim21 avatar Jun 23 '24 11:06 trim21

I'm afraid there hasn't been any progress so far.

masaushi avatar Jul 08 '24 00:07 masaushi

I don't think this is actually needed. It used to be the case that there were a lot of edge cases where defer wasn't inlined correctly, and thus could have (slightly) worse performance when unlocking a mutex with defer, however, the Go compiler in 95% of situations should inline it correctly now so it's not technically a defer in the typical sense.

lrstanley avatar Aug 10 '25 08:08 lrstanley