Skip to content

perf(interp): keep loop-carried locals in registers - #166

Merged
siyul-park merged 1 commit into
mainfrom
codex/issue-163-loop-carried-locals
Jul 30, 2026
Merged

perf(interp): keep loop-carried locals in registers#166
siyul-park merged 1 commit into
mainfrom
codex/issue-163-loop-carried-locals

Conversation

@siyul-park

@siyul-park siyul-park commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • keep eligible call-free loop-carried scalar locals authoritative in ARM64 registers across native back-edges
  • commit carried values on guard exits, fallbacks, safepoint yields, and module completion while preserving them across cache barriers and continuations
  • conservatively reject unsupported plans and retry without carried registers under register pressure
  • add planner/lowering regression coverage and document the ownership and benchmark results

Impact

Five-pair interleaved A/B medians on Apple M4 Pro (darwin/arm64, Go 1.26.2, -benchtime=300ms):

  • IterativeFib(30): 91.75 ns -> 36.75 ns (-59.9%)
  • TypedArraySum(256): 673.2 ns -> 307.7 ns (-54.3%)
  • Sieve(256): 2,645 ns -> 1,626 ns (-38.5%)
  • other canonical default medians stayed within 0.9%; allocations unchanged

Validation

  • make lint
  • make test
  • go test -race ./interp -count=1 -timeout=10m
  • targeted loop-carried/JIT ARM64 tests
  • make check-generated
  • make benchmark-pr
  • git diff --check

Closes #163

Summary by CodeRabbit

  • Performance

    • Improved ARM64 native loop execution by keeping eligible scalar values in registers, reducing repeated stack access.
    • Updated benchmark results and reproduction steps with refreshed cross-runtime measurements.
  • Bug Fixes

    • Improved correctness when native loops encounter exits, traps, safepoints, yields, and completion paths.
    • Added coverage for loop-carried values and register flushing behavior.
  • Documentation

    • Clarified native loop eligibility, register preservation, state transitions, and measurement methodology.

@siyul-park
siyul-park marked this pull request as ready for review July 30, 2026 15:26
@siyul-park
siyul-park merged commit 10d6adf into main Jul 30, 2026
1 check passed
@siyul-park
siyul-park deleted the codex/issue-163-loop-carried-locals branch July 30, 2026 15:27
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@siyul-park, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c6658b0-3e67-4f0e-a02b-5036feb5379a

📥 Commits

Reviewing files that changed from the base of the PR and between a5dad61 and 3567c12.

📒 Files selected for processing (8)
  • AGENTS.md
  • docs/benchmarks.md
  • docs/jit-internals.md
  • interp/jit.go
  • interp/jit_arm64.go
  • interp/jit_arm64_test.go
  • interp/jit_plan.go
  • interp/jit_plan_test.go
📝 Walkthrough

Walkthrough

Eligible call-free native loops now keep up to seven scalar locals authoritative in ARM64 registers across back-edges. The lowerer commits them on exits and state boundaries, with plan eligibility, correctness tests, benchmark procedures, and JIT ownership documentation updated.

Changes

Loop-carried register lowering

Layer / File(s) Summary
Loop-carried local eligibility
interp/jit_plan.go, interp/jit_plan_test.go
Plans identify read-and-written inline scalar locals in valid call-free backward loops, reject calls and oversized sets, and cover these cases with tests.
Carried-register lowering and commits
interp/jit.go, interp/jit_arm64.go, docs/jit-internals.md, AGENTS.md
ARM64 lowering carries eligible locals in X19–X25, updates them through LOCAL_SET, preserves them across cache invalidation, and commits them before exits, traps, yields, and completion.
Correctness tests and benchmark records
interp/jit_arm64_test.go, docs/benchmarks.md
ARM64 tests validate native results, side exits, safepoints, yields, and flush behavior; benchmark procedures and recorded results are refreshed.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Plan as staticPlan/tracePlan
  participant Lowerer as arm64Lowerer
  participant NativeLoop as Native loop
  participant VM as VM stack/interpreter
  Plan->>Lowerer: provide eligible carried locals
  Lowerer->>NativeLoop: keep scalar locals in X19-X25
  NativeLoop->>Lowerer: reach exit, yield, trap, or completion
  Lowerer->>VM: commit carried locals to VM slots
Loading

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-163-loop-carried-locals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

perf(interp): keep loop-carried locals in registers across native back-edges

1 participant