Outline cold opcode handlers from the VM dispatch loop - #709
Conversation
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 42151 uncovered lines. 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ApprovabilityVerdict: Approved e228128 This PR adds No code changes detected at You can customize Macroscope's approvability policy. Learn more. |
Merging this PR will not alter performance
Comparing Footnotes
|
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
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 ofVM::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, shrinksVM::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).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.