← Back to Pull requests

Regex: Add a lazily-populated cache for S_setup_EXACTISH_ST #25014

Open
unknown opened this pull request with 328 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 28, 2026 11:02 UTC
Author

S_setup_EXACTISH_ST() produces a quick next_matchable_info filter that is used to efficiently scan for positions before attempting a full pattern match. In blead, this filter is generated during regex execution and does not persist from one execution to another.

S_setup_EXACTISH_ST() does a fair amount of work, making its contribution to the runtime of pattern matching not insignificant. (Likely more noticeable for simpler patterns though.)

On the assumption that a regex that runs once will likely run again, it should be worthwhile to cache the result for future runs to retrieve.

This commit adds a lazily-allocated & populated cache for EXACTish regnodes. EXACTFL nodes are excluded from the cache, as the result of S_setup_EXACTISH_ST is dependent upon runtime locale and could conceivably change from one call to the next.

Using a pathological example of
my $x = "xy" x 100_000_000; while ($x =~ /x+y/g) {}, perf stats on blead looks something like this:

          9,869.16 msec task-clock                       #    0.999 CPUs utilized
    45,310,143,074      cycles                           #    4.591 GHz
     1,286,948,694      stalled-cycles-frontend          #    2.84% frontend cycles idle
   148,048,703,763      instructions                     #    3.27  insn per cycle
    28,107,399,294      branches                         #    2.848 G/sec
           925,475      branch-misses                    #    0.00% of all branches

with S_setup_EXACTISH_ST making a significant contribution:
  28.39%  perl     perl                  [.] S_setup_EXACTISH_ST.isra.0
  17.80%  perl     perl                  [.] S_regmatch
  15.81%  perl     perl                  [.] Perl_regexec_flags
  11.69%  perl     perl                  [.] Perl_pp_match
   5.11%  perl     perl                  [.] S_regrepeat
  .....

(That is excessive, S_setup_EXACTISH_ST is more likely to appear in the lower single digits.)

With the cache added:

          6,727.25 msec task-clock                       #    0.999 CPUs utilized
    30,689,491,323      cycles                           #    4.562 GHz
       189,078,312      stalled-cycles-frontend          #    0.62% frontend cycles idle
   120,343,823,540      instructions                     #    3.92  insn per cycle
    23,706,271,794      branches                         #    3.524 G/sec
           706,338      branch-misses                    #    0.00% of all branches

Closes #24480

-------------------------------------------------------------------------------

  • This set of changes does not require a perldelta entry.
  • Diff: 328 lines (+246 / -82) across 4 files Reviewer: demerphq Review duration: 48916m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.49) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 328 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.347
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #25014"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 49.1% (MEDIUM) · Higher = larger blast radius
    49.1%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 27.1% · Safe to merge
    27.1%
    Repository