Skip to content

perf(jit): inline pure scalar leaf callees at the optimized tier - #307

Merged
siyul-park merged 2 commits into
mainfrom
perf/jit-inline-leaves
Nov 9, 2026
Merged

siyul-park merged 2 commits into
mainfrom
perf/jit-inline-leaves

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

Step 5 (v1) of the #239 plan. spectral-norm's inner loops call a small non-recursive func(i32, i32) f64 n² times through a native call.

  • InlinePass (internal/transform/inline.go, Optimized tier only, ahead of O3) replaces a CALL of a statically resolved callee that is a pure scalar leaf (leaf: no call, handler, capture, write or allocation; scalar params/locals/results, i64 and refs excluded; ≤ 32 instructions; no backward branch) with the callee's promoted SSA body, spliced through the rebuilder (returns jump to a join carrying the results).
  • Deopt without new frames: every state in the inlined body is the CALL's own (stack holding callee + args at the CALL's IP). A deopt resumes the interpreter at the CALL, which re-runs the callee; a leaf writes nothing, so the re-run is unobservable. A feedback-guarded callee keeps its guard ahead of the body.
  • Bridge invariant: a bridge or callout runs the opcode at its state's IP with the state's stack, so exit() now requires that opcode to equal the exiting op's Code (compile.ErrInlined otherwise). An inlined op the machine declines (e.g. f64.rem) would otherwise run the CALL instead; Compile retries once without the inline pass. Three hand-built tests whose states named a different opcode were corrected; the full suite shows the check never fires without inlining.
  • Docs: pass-system.md (InlinePass), jit-internals.md (bridge invariant and retry).

Evidence

  • TestNewInlinePass: straight-line and forward-branch leaves inlined with every body op on the CALL's state; call kept for ref param, global write, nested call, loop, too large, handlers, captures.
  • TestLower "rejects a bridge whose state names another opcode"; TestCompile "inlines a leaf callee at the Optimized tier only" and "compiles again without inlining when an inlined operation would bridge" (red with the retry disabled).
  • TestWithThreshold "runs a call of a leaf callee as threaded does": direct and guarded callees, divisors including 0 (division-by-zero error equals threaded).
  • Three existing tests adapted: one callee padded past the size limit so its calls stay calls; two now wait on both tiers' entries (an inlined callee is never entered natively).
  • go test ./internal/... ./interp, make check, git diff --check: pass.
  • Local interleaved A/B (6 rounds, min, loaded machine): spectral-norm 16960 → 3907 ns (−77%); recursive-fib-20 unchanged. The CI benchmark report decides.

Found along the way, on main without this change: #306 (wrong JIT result after a speculated indirect callee changes and traps). The guarded-callee swap case is therefore not in this PR's parity test.

Refs #239

🤖 Generated with Claude Code

InlinePass replaces a CALL of a statically resolved pure scalar leaf
(no call, handler, capture, write or allocation; scalar params, locals
and results without i64 or refs; at most 32 instructions; no backward
branch) with the callee's promoted SSA body. Every state in the body is
the CALL's own, so a deopt resumes the interpreter at the CALL and
re-runs the pure callee unobserved; a feedback guard stays ahead of the
body. It runs only for the Optimized tier, ahead of O3.

A bridge or callout runs the opcode at its state's IP, so exit() now
requires that opcode to equal the exiting op's (compile.ErrInlined);
Compile retries once without inlining when an inlined op would bridge.

Refs #239

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9dfd6f97-04f9-4a2e-8446-cf6e1fbe0b50
Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@siyul-park
siyul-park merged commit bd97a16 into main Nov 9, 2026
1 check passed
@siyul-park
siyul-park deleted the perf/jit-inline-leaves branch November 9, 2026 15:53
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