← Back to Pull requests

interpreter: Skip the phi-node scan after most statements #65167

Closed
unknown closed this pull request without merging on Nov 23, 2026 19:39 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 22:25 UTC
Author

After every statement the interpreter called eval_phi, which scans the statements from the next one onwards for a phi block. A statement that is an expression, a branch, a return, a PhiC, an Upsilon or an SSA value ends that scan before it finds anything, and almost every statement in lowered code is one of these. eval_phi is now an inline wrapper that checks the first statement itself and calls the scan, renamed eval_phi_slow, only when a phi block might start there. Both use the same helper, ends_phi_block, to decide where a phi block ends, so the result is unchanged. Fall-through and branch targets both go through this one call site.

Benchmark

Three interpreted microbenchmarks (a loop of integer arithmetic, a loop calling a small function, a loop allocating a Ref), each run under --compile=min with Base.Experimental.@compiler_options compile=min. Measured with perf stat -e instructions:u,cycles:u, pinned to one core with taskset, on an AMD EPYC 9354. Each process ran either n = 1 or n = 3,000,000 iterations, and the median n = 1 count was subtracted to remove startup. 5 alternating reps per build. Baseline is the same master commit without this change. Values are per iteration, median [min–max]:

| benchmark | metric | master | this PR | change |
|---|---|---|---|---|
| loop | instructions | 8125.8 [8125.8–8125.8] | 7844.9 [7844.9–7844.9] | −3.46% |
| loop | cycles | 1677.0 [1654.3–1856.4] | 1624.3 [1589.0–1654.0] | −3.14% |
| calls | instructions | 6439.9 [6439.9–6441.9] | 6116.0 [6115.9–6116.0] | −5.03% |
| calls | cycles | 1327.4 [1317.1–1374.9] | 1269.4 [1262.1–1276.3] | −4.37% |
| allocs | instructions | 6854.5 [6854.5–6855.4] | 6559.5 [6559.5–6559.5] | −4.30% |
| allocs | cycles | 1412.2 [1404.7–1443.4] | 1344.4 [1338.8–1373.1] | −4.80% |

The saving comes entirely from the statement-kind check. A build whose wrapper only checks to >= ns before calling eval_phi_slow is 1.1% above master in instructions on all three benchmarks, and one that always calls eval_phi_slow is 0.2% above master.

Testing

  • interpreter, core, exceptions and Compiler/ssair pass. Compiler/ssair includes Compiler/test/interpreter_exec.jl both normally and under compile=min, and that file runs hand-built thunks with phi blocks after GlobalRef/QuoteNode statements and after branches.

  • With the whole process under --compile=min, core, iterators, tuple, dict, exceptions, arrayops, strings/basic and functional gave identical pass/fail/broken counts and identical failing test locations on master and on the first version of this branch; iterators, tuple and functional give the same results again on the current version. Some of these files already fail under --compile=min on master, and core.jl segfaults at the same line on both builds.

  • OpaqueClosures built with do_compile=false from optimized IRCode containing PhiNodes (two loop functions) give the correct results. Under gdb (on the first version of this branch) they run in the interpreter and evaluate a nonempty phi block from the new call site.

  • make -C src analyze-interpreter is clean.
  • This patch was written with Claude Code.

    Diff: 404 lines (+303 / -101) across 5 files Reviewer: Keno Review duration: 1273m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 404 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #65167"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%