gh-127119: Remove check on accidental deallocation of immortal objects for free-threaded build#127120
gh-127119: Remove check on accidental deallocation of immortal objects for free-threaded build#127120eendebakpt wants to merge 17 commits into
Conversation
|
Apparently, assertion is broken in tests. |
Sorry, something went wrong.
Yes, my mistake. Should be fixed now |
Sorry, something went wrong.
…e-127119.p9Yv4U.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ZeroIntensity
left a comment
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 4dc97c9 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
Sorry, something went wrong.
CI is failing, because apparently you can build with assertions but not with debug enabled (that's what I get for prematurely approving, ha).
ZeroIntensity
left a comment
There was a problem hiding this comment.
LGTM (again)!
Sorry, something went wrong.
There was a problem hiding this comment.
this changes from silently re-immortalizing the small ints to actually letting them be deallocated in non-debug builds. in theory this is supposed to be fine, but how confident are we of (buggy) reference counting code not relying in the former behavior?
(I'm not blocking this PR, I think the change is acceptable, just want that pondered...)
Sorry, something went wrong.
I thought about that too, but I think issues around immortal objects being buggy was fixed by GH-125251 (at least, I thought that was implied by the removal of |
Sorry, something went wrong.
|
The possibility of de-allocating immortal objects is described in [PEP 683, section Accidental De-Immortalizing](https://peps.python.org/pep-0683/#accidental-de-immortalizing). Also see But if I understand the correctly the accidental-de-immortalizing cannot happen on: 64-bit systems, or with the free-threading build, or when And yes, this should be double checked! |
Sorry, something went wrong.
|
Results on a microbenchmark: I expect no overall improvement on the pyperformance benchmark. Benchmark script |
Sorry, something went wrong.
ZeroIntensity
left a comment
There was a problem hiding this comment.
This is now incorrect :(
Sorry, something went wrong.
|
As an alternative to removing the check altogether we could make it cheaper by using the reserved bit https://github.com/python/cpython/blob/main/Include/cpython/longintrepr.h#L79 as a marker for immortal/small ints. |
Sorry, something went wrong.
|
@markshannon Thanks for the idea! I think it works and would not be hard to implement, but I am a bit hesitant to use a reserved bit for a small optimization like this. I created an alternative PR with a faster check based on your idea though |
Sorry, something went wrong.
|
That bit is reserved for exactly this use case, so it is fine to use it. |
Sorry, something went wrong.
(Description was updated) The python small ints are immortal with a fixed reference count (also some other types). However, old extension modules can still modify the reference count and end up deallocating these objects.
This should not be an issue on 64-bit builds (even when accidentically changing the reference count it will take a very long time for an object to reach refcount zero) or the free-threaded build (which used a different reference counts, so has no legacy extensions modules)
In this PR we remove the check on accidental deallocation for the free-threading build. This has performance impact for the long type (where the
tp_deallocis actually called often). For the other types we remove it to be consistent, but it should have no performance impact.Also see: