godux
godux copied to clipboard
More idiomatic lock/unlock logic
Defer is more idiomatic and protects from any future errors ensuring that it mutex will be always unlocked.
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.
No, just to make sure to always unlock. Not sure how omitting defer optimization makes sense for something like godux.
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?
Really, I have no plans to argue about this. If you believe this makes things slower - sure, drop it. No hard feelings there.
Actually I don't have a strong position about this. Just wanted to start the discussion...
[I'm not the maintainer of the project]