gh-155725: Remove PyGILState_Ensure usage from tracemalloc - #156409
Conversation
tracemalloc no longer acquires the GIL nor creates a temporary thread state when tracing memory allocations. A thread with no attached thread state now records the trace with the "<unknown>" traceback instead of attaching a thread state to capture the Python traceback. Threads without a thread state used to pay for a GIL acquisition plus a full thread state creation and destruction on every traced raw allocation, only to record an empty traceback anyway.
Documentation build overview
|
…e attached Store traceback frame filenames as interned NUL terminated UTF-8 strings instead of Python str objects, so that capturing a traceback no longer uses or modifies Python objects. Threads without an attached thread state now capture their Python traceback by walking the frames of the thread state most recently bound to the thread; only threads which never had a thread state record the traceback as "<unknown>".
ZeroIntensity
left a comment
There was a problem hiding this comment.
Thanks, this is a much better approach.
gpshead
left a comment
There was a problem hiding this comment.
agreed that this is the right thing to do. maybe mention in the NEWS entry that the printed filename format changes slightly for higher value Unicode, it's a utf-8 value with \xNN escapes rather than using a mix of \xNN \uNNNN and \UNNNNNNNN. in practice it should not be a big deal, its debugging data and all the data is there.
|
Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-156628 is a backport of this pull request to the 3.15 branch. |
…GH-156409) (#156628) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
|
|
tracemalloc no longer acquires the GIL nor creates a temporary thread state when tracing memory allocations.
tracemallocraw-domain allocator hook violatesPYMEM_DOMAIN_RAWcontract #155725