-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider moving from sync.RWMutex to sync.Mutex #4536
Comments
Worth noting that for |
First, I don't think fyne application are seriously impacted by the big reported against go. How many desktop currently have 16 or more core. Now the reasoning to use rwmutex is to allow reader to have fast and unblocked access. Most case in a ui should be read with little write. If we have heavy writer case, then that's something to look into first and see if we could switch more to read. |
Indeed. It does however document a few cases where it is better (mostly reads or caches that only grow, I think). We do have a few uses of it already It might be a case that some of those should just use a mutex though. |
Absolutely. It is worth noting that I have gotten the understanding from Gophers Slack (#performance etc.) that RWMutex generally is discouraged in favour of a regular Mutex |
Yeah, #performance has usually a very different profile usage than fyne applications. I wish I had 192 core cpu :-D |
I don't think it was about the issue about scaling but more of a general idea that Mutex might be better and faster in many other situations. My benchmarking does show that for the same 1:1 locking it can be considerably slower when there is no contention. |
Checklist
Is your feature request related to a problem?
We rely quite heavily on
sync.RWMutex
within the project and it might not always be the magical performance improvement compared tosync.Mutex
that we might sometimes think it is. Most notably, there is the issue of golang/go#17973. TheRWMutex
type is also larger so takes up more space in the cache line (golang/go#17973 (comment)) plus it is more complicated internally so acquiring locks is slower thatMutex
in cases where there is no lock contention.As part of benchmarking #4509 (comment), I got the following numbers when testing atomic vs mutexes with no lock contention. Take it with a little grain of salt given that the idea with
RWMutex
is to be faster for simultaneous accesses (read/write) and this test is only considering single-threaded usage:Is it possible to construct a solution with the existing API?
Yes. We can evaluate using
Mutex
in some cases and maybe even switching tosync.Map
orsync/atomic
in some cases.Describe the solution you'd like to see.
We need to benchmark our use cases and see if
sync.RWMutex
is helping us or hurting us in terms of performance.The text was updated successfully, but these errors were encountered: