Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-108634: Py_TRACE_REFS uses a hash table#108663
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Py_TRACE_REFS adds
These changes have no impact on the ABI. So the Py_TRACE_REFS is now ABI compatible with release and debug builds. |
!buildbot TraceRefs |
bedevere-bot commentedAug 30, 2023
Oh, it seems like "AMD64 Arch Linux TraceRefs 3.x" buildbothttps://buildbot.python.org/all/#/builders/484 is not used from this GitHub command, |
|
Failed builds:
test_zippath_from_non_installed_posix() and test_upgrade_dependencies() of test_venv failed: known issue#103224, unrelated to this PR. |
I'm not qualified to review this, but nevertheless, here's my unqualified opinion: the idea of using a hash map instead of patching the object layout seems good to me; making the trace ref build ABI compatible with ordinary build seems like a big win. I'll leave the proper review to someone who knows the GC better (for example, Pablo was already CC'd on this PR). The configure changes are fine. |
Uh oh!
There was an error while loading.Please reload this page.
* test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace().
I removed the force parameter and rebased the PR on the main branch. |
How often is Py_TRACE_REFS used? Did you measure the overhead of your new implementation compared to the old one? |
For a debug build, I don't really care of the memory usage (if it's "reasonable"). For example, enabling tracemalloc to trace Python memory allocation almost doubles the Python memory usage! This PR increases the peak memory usage of a
As far as I know, the main user is@pablogsal's TraceRefs buildbot which makes sure that Python still builds successfully with Py_TRACE_REFS (and that the test suite pass, as well). On Python 3.7 and older, I expect that the main difference of my change is the memory usage. I measured it with:
Python built with: Memoy usage of Py_REF_DEBUG + Py_TRACE_REFS:
I ran the command 3 times, the first run has a higher peak memory usage, maybe because the first one used more memory to build PYC files. By the way, For comparison, memory usage of Py_REF_DEBUG (without Py_TRACE_REFS):
On themain branch, Py_TRACE_REFS adds1 172 kiB (+11%). |
Well, why do we care about improving Py_TRACE_REFS if we think nobody uses it? :-) |
vstinner commentedAug 30, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I would like to convert some stdlib C extensions to the limited C API:
Thepractical problem is that we do have a TraceRefs buildbot, and I care of having only green buildbots. Also, since it's unclear to me who uses TraceRefs, I prefer to fix it rather than ask who use it, or propose to deprecate/remove the feature. In the past, I removed COUNT_ALLOCS build, but this one was used by no one, and there was no buildbot :-) Right now, trying to workaround TraceRefs build error with Py_LIMITED_API causes me headaches... I wrote atrivial PR to convert the In short, fixing Py_LIMITED_API support for Py_TRACE_REFS lookssimpler to me than trying to workaround Py_TRACE_REFS build errors :-) Also, well, IMO it'snice to have the same ABI for all Python builds! It should make these builds usable in more cases. I always wanted to give a try to the hash table idea. As you can see, it's not that complicated. |
On my _stat PR,@AA-Turner seems to be worried of breaking TraceRefs buildbot:#108573 (comment) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hmm, I don't think I have ever used Py_TRACE_REFS for CPython core development. |
I don't use Py_TRACE_REFS for that:https://vstinner.github.io/debug-python-refleak.html I'm not sure what are the use cases of Py_TRACE_REFS and the |
This comment was marked as off-topic.
This comment was marked as off-topic.
vstinner commentedAug 31, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I checked that this change does not introduce new memory leak:
There is no leak. For comparison, if I comment _PyObject_FiniState() in PyInterpreterState_Delete(), leak on purpose for the test:
|
Commit13a0007 (python#108663) made allPython builds compatible with the Limited API, and removed theLIMITED_API_AVAILABLE flag. However, some tests were still checkingfor that flag, so they were now being incorrectly skipped. Removethese checks to let these tests run again.Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Commit13a0007 (python#108663) made allPython builds compatible with the Limited API, and removed theLIMITED_API_AVAILABLE flag. However, some tests were still checkingfor that flag, so they were now being incorrectly skipped. Removethese checks to let these tests run again.Signed-off-by: Anders Kaseorg <andersk@mit.edu>
#ifdef Py_TRACE_REFS | ||
#undef LIMITED_API_AVAILABLE | ||
#else | ||
#define LIMITED_API_AVAILABLE 1 |
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.
This flag is still referenced inModules/_testcapi/heaptype_relative.c
,Modules/_testcapi/vectorcall_limited.c
,Modules/_testcapimodule.c
, which means the limited API tests are now being incorrectly skipped unconditionally.
…09046)Commit13a0007 (#108663) made allPython builds compatible with the Limited API, and removed theLIMITED_API_AVAILABLE flag. However, some tests were still checkingfor that flag, so they were now being incorrectly skipped. Removethese checks to let these tests run again.Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Uh oh!
There was an error while loading.Please reload this page.
Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API.
Change Py_TRACE_REFS build:
Test changes for Py_TRACE_REFS:
📚 Documentation preview 📚:https://cpython-previews--108663.org.readthedocs.build/