Closed jsign closed 5 years ago
This seems reasonable. Add
only has a single return so the value of using a defer
is lost anyways.
If you like I could make a PR applying this idea when possible, and see there the bench results and decide.
@jsign that sounds good to me. Thanks!
I want to share a similar exploration I've made in other project regarding the impact on
defer
.I avoid using
defer
in theAdd
method with some interesting results. Considering there wasn't a benchmark forAdd
, I created one. Using this new benchmark, I tested the actual implementation and this new one.The end results are:
This means that not using
defer
seems to have a considerable impact inns/op
ofAdd
.What are those sub-benchs? Just applying the same idea of bitcask to test if the
meta
size has some influence on the results. Seeing the implementation, it shouldn't and the results seem to reflect that. (so we can ignore the sub-benchmarks if you like, I kept them just in case).How to reproduce these results? (not completely elegant, but enough to show the experiment)
Small explanation:
Add
benchcmp
.This idea may apply to other parts where
defer sync.Mutex.Unlock()
exists.In the case of bitcask, the impact was close to 4%, here seems to be greater. If I'm not missing something, looks like the
Add
function is quite fast anddefer
overhead is relatively big (relatively).