Description
It's occasionally useful to be able to link information to active frames. Two recent examples:
- https://stackoverflow.com/questions/72270154/weakref-weakkeydictionary-to-frame-frametype-objects
- gh-102864: Remove access to f_locals in pdb #102865
Currently, since frames don't support being weakly referenced, custom lifecycle management is required in this case. That's unfortunate because errors in cleaning out the references will lead to memory leaks of dead frames and their respective locals.
The straightforward solution is to add weakref support to frame
objects. The performance hit is limited to setting NULL on the f_weakreflist
field on frame object creation, and later a NULL check (for whether there are any weakrefs) at the frame object's deallocation. This is what the related PR does.
I ran the PR and the base main
branch at the time against pyperformance 1.0.6. The raw results are in benchmarks.zip but the gist is that there are no significant differences between the two branches in any of the benchmarks executed.