GeezerVison is showing github.com — GH-124715: Move trashcan mechanism into `Py_Dealloc` by markshannon · Pull Request #132280 · python/cpython
Conversation
markshannon
commented
Apr 8, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This is a good idea, IMHO. I had a similar PR but Mark's is more elegant than mine.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Apr 8, 2025
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Initial performance numbers are a bit down. 0.2% - 1.6% slower.
I'm testing another branch that adds PyThreadState * as a parameter to _PyDealloc, which might reduce the impact.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
With faster recursion checks, performance is mixed but no worse overall:
- Linux ARM: 0.4% slower
- Linux x86: 1.5% slower
- Windows x86: 0.9% faster
- Mac (ARM): 3.8% faster
Although the 1.5% slowdown on linux x86 is concerning.
I also tried passing in the thread state as a parameter to _Py_Dealloc which is a much larger change. Results were a bit worse than this PR:
- Linux ARM: no change
- Linux x86: 1.3% slower
- Windows x86: 1.3% slower
- Mac (ARM): 3.9% faster
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Maybe perf will be better with just one additional if for a decref that is not a container. So you have an implementation of decref for containers, and do one if to decide whether to apply it or stay with the current one.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Maybe perf will be better with just one additional if for a decref that is not a container. So you have an implementation of decref for containers, and do one if to decide whether to apply it or stay with the current one.
Do you mean a test in Py_DECREF or in Py_Dealloc?
We really want to avoid adding more branches to Py_DECREF as Py_DECREF is inlined in so many places.
Adding a branch in Py_Dealloc would save the stack checks, but those are cheap. Getting the "margin" is a load, subtract and shift.
Testing for collections is more expensive. PyObject_IS_GC does three loads, two of which are dependent on the first.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Maybe perf will be better with just one additional if for a decref that is not a container. So you have an implementation of decref for containers, and do one if to decide whether to apply it or stay with the current one.
Do you mean a test in Py_DECREF or in Py_Dealloc?
Sorry, yeah, dealloc. Maybe not worth it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
The overall design LGTM.
I added a few comments.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot s390x RHEL8 3.x (tier-3) has failed when building commit 44e4c47.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/509/builds/9127) and take a look at the build logs.
- Check if the failure is related to this commit (44e4c47) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/509/builds/9127
Failed tests:
Failed subtests:
- test_async_global_awaited_by - test.test_external_inspection.TestGetStackTrace.test_async_global_awaited_by
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x/build/Lib/test/test_external_inspection.py", line 531, in test_async_global_awaited_by
self.assertEqual([[['echo_client_spam'], 'echo client spam', [[['main'], 'Task-1', []]]]], entries[-1][1])
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Lists differ: [[['echo_client_spam'], 'echo client spam', [[['main'], 'Task-1', []]]]] != []
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Hi! The buildbot s390x RHEL8 3.x (tier-3) has failed when building commit 44e4c47.
test_recursive_pickle (test.test_functools.TestPartialPy.test_recursive_pickle) ...
Objects/classobject.c:247: _PyObject_GC_UNTRACK: Assertion "_PyObject_GC_IS_TRACKED(((PyObject*)(op)))" failed: object not tracked by the garbage collector
Enable tracemalloc to get the memory block allocation traceback
object address : 0x3ffae27c8f0
object refcount : 0
object type : 0x1669768
object type name: method
object repr : <refcnt 0 at 0x3ffae27c8f0>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized
Current thread 0x000003ffb6177270 [python] (most recent call first):
File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x/build/Lib/test/test_functools.py", line 420 in test_recursive_pickle
(...)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
added a commit
to vstinner/cpython
that referenced
this pull request
Apr 30, 2025
Replace _PyObject_GC_UNTRACK() with PyObject_GC_UnTrack() to not fail
if the method was already untracked.
|
I wrote #133199 to fix test_functools.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 25, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|