-
Notifications
You must be signed in to change notification settings - Fork 719
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
Two minor pool optimizations #3250
Conversation
FWIW, the dirty flag was originally an optimization (see #1608), interesting to see that it's not so any longer, at least on those benchmarks. |
I did look at that commit and my interpretation is that the main improvement was replacing two locks by one. As for the flag, I can't really see it helping from a theoretical point of view as locking the uncontended lock is also only an atomic RMW operation which will almost surely bring in the cache line containing the two length fields. And it cannot help in the contented case as this means the pool is definitely dirty as only the single holder of the GIL will acquire it for cleaning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I am 100% in favour of the removal of the atomic from the ReferencePool
.
For the change to OWNED_OBJECTS
, my only concern is that we might accidentally break the implementation in future to make it unsound without noticing. I'm unsure if a test can guard against this. Perhaps there can be a debug_assert!
of some kind to protect against reentrancy (maybe using a second static which tracks reentrancy?). The idea being to have some protection against unsafely but no impact on release mode...
If we are fine with the complexity, it can be made to use |
So here's the
IMO this is another signal that this optimisation does have positive impact (albeit slight). The number of code lines which would pay in complexity is not that high, so it seems reasonable to me to use |
…eigh the improvement compared to locking an uncontented mutex.
…void the runtime checking overhead.
Added this as a separate commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Not sure if this is worth it while we are trying to get rid of it, but there is some free performance on the table here and this could also be part of a 0.19.x point release.
The pytests benchmarks improve slightly from
to