-
Notifications
You must be signed in to change notification settings - Fork 761
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
Potential enhancement: GIL-based Mutex #1877
Comments
Acquiring an uncontested mutex is really cheap. I think you're overestimating the overhead associated with that. Especially the difference between it and a RefCell, and the relative costs when things like once_cell/lazy_static get involved. It's shame we can't guarantee unique access with the Python token (it's Copy), this would have been a cool application for it. |
Ah, hadn't thought about the uncontested part. I don't need So I guess next step would be a benchmark to see if it makes a difference. |
This is actually very similar to the At that point I think it definitely makes sense to make it a reusable API which users could wrap around individual fields; that would enable a kind of interior mutability for So in summary, yes, I would argue there is space for this concept in PyO3. However, I would prefer not introduce it until after we have implemented #1068, because at the moment I think it conflicts a bit with the existing (I also think that given this is a wrapper around |
Now that we've added |
A passing thought: how is this impacted by the possibility of multiple sub-interpreters (and eventually multiple GILs - see PEP 684)? |
Isn't this eventually fixed by #2975 ( |
Yes, I think |
Change the milestone as we released this as part of 0.18.3. (The impact of PEP 684 is also not clear but that affects all GIL-based synchronization in PyO3, e.g. at least |
I have found myself creating statics that are accessed only by threads that have the GIL. As such, use of a normal Mutex is unnecessary performance overhead (and this matters somewhat in my use case, a profiler).
There is
Py<T>
, but that assumesT
is a Python object, so random Rust objects are harder.So, here is a sketch of a GIL-based Mutex:
The text was updated successfully, but these errors were encountered: