Skip to content

Outline cold opcode handlers from the VM dispatch loop - #709

Open
samuelcolvin wants to merge 1 commit into
mainfrom
assembly
Open

Outline cold opcode handlers from the VM dispatch loop#709
samuelcolvin wants to merge 1 commit into
mainfrom
assembly

Conversation

@samuelcolvin

@samuelcolvin samuelcolvin commented Aug 11, 2026

Copy link
Copy Markdown
Member

Mark ten cold handler methods (unpack_ex, dict_merge, with-statement ops, exception match/unwind, kw method calls, import attr loads) #[inline(never)] so their bodies stay out of VM::run.

This frees enough registers for the hot loop to keep the cached code pointer live instead of reloading it from a spill slot on every opcode.

Claude-Session: https://claude.ai/code/session_01HbZqFxoKRfCeBgU239PMij


Summary by cubic

Outlined ten cold opcode handlers with #[inline(never)] to move them out of VM::run’s dispatch loop. This lowers register/I-cache pressure, keeps the cached code pointer in a register, shrinks VM::run ~4%, and delivers ~1% geomean speedups with 0.7–3.6% wins on interpreter-heavy benches and ~1% regressions on a few (json_dumps, end_to_end, func_call_kwargs).

  • Refactors
    • Handlers outlined: load_attr_import, exec_call_attr_kw; dict_merge, method_dict_merge, unpack_ex; exec_before_with, exec_with_exit, exec_with_except_start, handle_exception_with_value, check_exc_match.

Written for commit db30bd3. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 42151 uncovered lines.
✅ Project coverage is 56.7%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    56.70%    56.70%        —%
==========================================
  Files          407       407         —
  Lines        97342     97342         —
  Branches    207204    207204         —
==========================================
+ Hits         55191     55191         —
- Misses       42151     42151         —
- Partials      3969      3969         —

Generated by Codecov Action

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@macroscopeapp

macroscopeapp Bot commented Aug 11, 2026

Copy link
Copy Markdown

Approvability

Verdict: Approved e228128

This PR adds #[inline(never)] attributes to cold VM opcode handlers for I-cache optimization. The changes are purely mechanical compiler hints with no behavioral impact - only inlining decisions are affected. No logic, runtime behavior, or APIs are modified.

No code changes detected at db30bd3. Prior analysis still applies.

You can customize Macroscope's approvability policy. Learn more.

@codspeed-hq

codspeed-hq Bot commented Aug 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 34 untouched benchmarks
⏩ 16 skipped benchmarks1


Comparing assembly (db30bd3) with main (ca9cca0)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Mark ten cold handler methods (unpack_ex, dict_merge, with-statement
ops, exception match/unwind, kw method calls, import attr loads)
#[inline(never)] so their bodies stay out of VM::run. This frees enough
registers for the hot loop to keep the cached code pointer live instead
of reloading it from a spill slot on every opcode.

Effect measured over four alternating-order criterion rounds (see
performance_findings.md): ~1% geomean improvement, with sign-stable
wins of 0.7-3.6% on interpreter-bound benches (empty_tuples -3.6%,
fstring_report -2.6%, datetime_ops/dict_comp -2.2 to -2.4%) and small
(~1%) regressions on json_dumps/end_to_end/func_call_kwargs. CodSpeed
reports no significant change. Defensible mainly on code-organisation
grounds: VM::run shrinks ~4% and no longer spills the cached code
pointer in the dispatch loop.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HbZqFxoKRfCeBgU239PMij
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant