godux icon indicating copy to clipboard operation
godux copied to clipboard

More idiomatic lock/unlock logic

Open themalkolm opened this issue 8 years ago • 5 comments

Defer is more idiomatic and protects from any future errors ensuring that it mutex will be always unlocked.

themalkolm avatar Oct 28 '16 09:10 themalkolm

Any comments about performances?

...lately I came across this blog post where about the use of defer you can read:

The point is defer is not a zero-cost abstraction. We can benchmark it to show the performance overhead. In this benchmark, we compare locking a mutex and unlocking it with a defer in a loop to locking a mutex and unlocking it without defer.

splendido avatar Oct 28 '16 09:10 splendido

No, just to make sure to always unlock. Not sure how omitting defer optimization makes sense for something like godux.

themalkolm avatar Oct 28 '16 11:10 themalkolm

It's not that big of a loss in performances but maybe when used on the server side to feed microservices with state changes could be worth it?

splendido avatar Oct 28 '16 12:10 splendido

Really, I have no plans to argue about this. If you believe this makes things slower - sure, drop it. No hard feelings there.

themalkolm avatar Oct 28 '16 12:10 themalkolm

Actually I don't have a strong position about this. Just wanted to start the discussion...

[I'm not the maintainer of the project]

splendido avatar Oct 28 '16 15:10 splendido