← Back to Pull requests

regex: Lifetime cell reuse and ContinueRunningNormally through the portal #409

Closed
unknown closed this pull request without merging on Nov 29, 2026 13:10 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 11:34 UTC
Author

Follow-up to #405: more per-event host overhead removed on the majit/examples/regex callgrind slope. The RPython build of the same benchmark runs at 12,452 Ir/char.

| point | Ir/char |
|---|---:|
| tip of #405 | 15,557 |
| regalloc Lifetime cells reused | 15,361 |
| CRN reaches the portal (this PR's tip) | 15,245 |

Commits

  • Reuse regalloc Lifetime cells across compilations. LifetimeManager overwrites the cells of earlier compilations in place (Rc::get_mut) and charges the translated regalloc.py Lifetime size to the host clock, so the JIT counter decay matches a fresh allocation.

  • Serve IntBoundRc cells from a bounded per-thread free list, then its revert. The free list saved 7 Ir/char (15,361 → 15,354), because the 48-byte blocks were already served from the glibc tcache. Both commits are kept so the measurement is on record; together they change nothing.

  • Let the blackhole's ContinueRunningNormally reach the portal. resume_in_blackhole now hands the original JitException to the portal (blackhole.py _run_forever → warmspot.py ll_portal_runner / handle_jitexception) instead of turning it into a PortalResume.

  • - The generated can_enter_jit consumer matches PortalControl. apply_portal_crn restores the reds, the greens are read by reference, and the args box goes back onto merge_point_args_scratch (blackhole.py recycle_merge_point_args).
    - This removes the PortalResume swap, the outcome match and three callback checks from every guard failure.

    Stats

    MAJIT_STATS=1 PYRE_REGEX_ROWS=2 PYRE_REGEX_LENGTHS=1048576, shortcircuit: bridges go from 8155 to 8157; host clock ticks are 775 in both.

  • I diagnosed the difference by logging host allocations up to the first guard failure in both builds. The first divergence is two 32-byte bank regrows in bhimpl_jit_merge_point after a CRN. They happen on the old path only: it swapped the args into the PortalResume scratch and returned an empty box to the pool.

  • That path charged both the translated ContinueRunningNormally size and the host regrow, and the extra bytes moved the decay earlier. The new path charges only the translated size.

  • At 64K chars the counts are 921 → 922; at 256K they are 3292 in both.
  • Verification

  • cargo test --release --features dynasm passes for majit-macros, majit-metainterp, regex, tl, tlc, tla, tlr, tiny2, tiny3, tinyframe, braininterp, spcount, dualtape, i64env and cel.

  • regex also passes under MAJIT_STRICT=1 and under PYPY_GC_NURSERY=65536.

  • The pre-commit hooks, citation, boundary and header checks, and build-jit-core.sh --check all pass.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01N1Sftb4SjjFgFkCvtBLvpi

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Improved handling of JIT back-edge outcomes, including exceptions, resumes, and state restoration.
    Ensured pending finish operations are processed before returning through a back edge, including when portal entry returns a pointer.
    Performance
    * Reduced repeated lifetime-management work during compilation by reusing scratch storage.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 420 lines (+315 / -105) across 5 files Reviewer: youknowone Review duration: 95m
    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 · 420 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.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #409"
    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: 45% (MEDIUM) · Higher = larger blast radius
    45%
    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.8% · Safe to merge
    17.8%