bpo-35053: Enhance tracemalloc to trace free lists by vstinner · Pull Request #10063 · python/cpython
tracemalloc now tries to update the traceback when an object is
reused from a "free list" (optimization for faster object creation,
used by the builtin list
Changes:
- Add _PyTraceMalloc_NewReference() function which tries to update
the Python traceback of a Python object. - _Py_NewReference() now calls _PyTraceMalloc_NewReference().
tracemalloc now tries to update the traceback when an object is reused from a "free list" (optimization for faster object creation, used by the builtin list Changes: * Add _PyTraceMalloc_NewReference() function which tries to update the Python traceback of a Python object. * _Py_NewReference() now calls _PyTraceMalloc_NewReference().
I also optimized _PyTraceMalloc_NewReference() to make it faster when tracemalloc is tracing memory allocations.
@methane: Ok, the PR is now waiting for your review :-)
@methane: Thanks for the review!
While reviewing one last time before merging, I found a potential issue: traceback_new() was called when tables were not locked, whereas all other calls to traceback_new() are done with tables locked. I moved the traceback_new() call inside TABLES_LOCK/TABLES_UNLOCK to make the code safer and faster (traceback_new is avoided if it's not needed, if the object is not tracked by tracemalloc).