Repository navigation
perf: index stack-held sequences and read closure cells in line - #87
Merged
Merged
Conversation
Two shapes in generator expressions and closures left compiled code for a helper on every execution: - c[i] with c on the operand stack (a closure variable, an attribute, a call's result) rather than a local went through h_subscr_ref. The in-line list and tuple index now also takes a stack-held container that another owner keeps alive, which leaves by a plain decrement; a container the release would free still takes the helper. - LOAD_DEREF called h_load_deref. It now reads the cell in line, through a CellLayout probed at startup like the list and tuple layouts: the frame's cells vector, the cell's borrow counter and its value, with the helper for an index out of range, a borrowed cell, or an unbound value. len(set(vec[i] + i for i in cols)) retires 4.7% fewer instructions, nqueens 4.2%, sudoku 1.5%, generators_tree 1%.
owenthcarey
added a commit
that referenced
this pull request
Oct 22, 2026
Brings in #87 to #91. The conflict with #91's chunked frame compiles in `Lower` keeps both: `never_ran` is computed from `starts` before `self.starts = starts`. Also fixes two problems the branch's CI found: - Windows builds failed on `make_struct_time_tz`, which only the Unix `localtime` path calls (a dead-code error under `-D warnings`); it is now `#[cfg(unix)]`. - The `dict_ops` bench fixture ran 1.27x the merge base's instructions (CI: 1.32x on Linux, 1.43x on macOS). Its `bench` compiles at a back edge of its first loop, during its only activation, so the later loops had not run yet and their blocks looked never-run (their `isinstance` and `list` reads were unresolved): they ran in the core loop. Blocks are now left out only for code compiled after finishing many activations (call heat); code a loop made hot compiles whole. dict_ops now matches main (591.2M vs 590.5M instructions).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the plan in
docs/PERFORMANCE-PROGRESS.md(on #86): fewer helper calls from compiled code.Two shapes common in generator expressions and closures left the frame JIT's native code for a helper on every execution:
c[i]withcon the operand stack (a closure variable, an attribute, a call's result) went throughh_subscr_ref. The in-line list and tuple index (seq_index) took only a local container; it now also takes one the stack holds, when another owner keeps it alive (it leaves by a plain decrement). A container the release would free still takes the helper.LOAD_DEREFcalledh_load_deref. It now reads the cell in line through aCellLayoutprobed at startup, like the list and tuple layouts (the frame's cells vector, the cell's borrow counter and its value), falling back to the helper for an index out of range, a borrowed cell, or an unbound value.Measurements
Instructions retired per steady-state call (
quickbuild, pinned hash seed), againstmain:nqueenssudokugenerators_treeclosures_decoratorscomprehensionschaoslen(set(vec[i] + i for i in cols))withveca closure variable retires 4.7% fewer instructions.Validation