Uh oh!
There was an error while loading. Please reload this page.
gh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW - #148999
gh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW#148999ljfp wants to merge 2 commits into
Conversation
ebd2c01 to
bb9166bCompareCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Hey @Fidget-Spinner , following up on your earlier comment: #133721 (comment) It took me way longer than expected (almost a year!), but I’ve now opened this replacement PR which I hope fixes the issues found in the previous one. Compared with the earlier PR, this version has a cleaned-up branch history and includes several correctness fixes found while chasing CI failures. In particular, the borrow-safety analysis now checks paths through exception handlers, avoids optimizing copied stack references into This new PR is passing tests now, and I think it’s ready for review. |
The
LOAD_FAST_BORROWinstruction loads a borrowed reference onto the operand stack, which is a performance optimization that avoids unnecessary reference counting operations.Previously, we were only applying this optimization when the reference was consumed within the same basic block. If the value was still on the stack at the end of a basic block (indicated by the
REF_UNCONSUMEDflag), we wouldn't perform the optimization.However, there are cases where it's safe to use
LOAD_FAST_BORROWeven when the value is still on the stack at the end of a basic block. The optimization is safe as long as every successor path preserves the supporting reference in the frame until the borrowed reference is consumed, including paths through exception handlers.This fix allows us to optimize more cases, which seems to be particularly important for the virtual iterators implementation (PR #132555) where the iterable for a loop is often live at basic block end.
Fixesgh-133672.
Supersedes gh-133721.