[SPARK-59531][SQL] Avoid a per-match MatchResult allocation in regexp_extract, regexp_extract_all, and regexp_instr #58815
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 265 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.334
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #58815"
general
weight: 0.35
stevomitric
What changes were proposed in this pull request?
RegExpExtractBase.extract,RegExpExtractBase.extractAll, andRegExpInStrcallMatcher.toMatchResult()on every match, then readgroupCount/group(idx)(the extracthelpers) or
start()(regexp_instr) from the returned snapshot:Matcher.toMatchResult()allocates an immutableMatchResultsnapshot of the current matchstate, including a copy of the groups
int[]. This PR reads the same values directly from theMatcher:and
m.toMatchResult().start()->m.start()inRegExpInStr(both the interpreted and thecodegen paths).
Why are the changes needed?
The values are read immediately after
find(), with nothing else mutating the matcher inbetween, so
Matcher.groupCount(),Matcher.group(int), andMatcher.start()return exactlythe same values as the corresponding
MatchResultmethods for the current match. Snapshottinginto a
MatchResultfirst only adds one allocation (the snapshot plus a copy of the groupsint[]) per match on theregexp_extract,regexp_extract_all, andregexp_instrhot paths.Profiling a
regexp_extractworkload under JFR (settings=profile) showsjava.util.regex.Matcher.toMatchResultaccounting for ~5% of sampled allocation pressure;this change removes it. Wall-clock time is unchanged within run-to-run noise (this is an
allocation / GC-pressure reduction, not a CPU one).
Does this PR introduce _any_ user-facing change?
No.
How was this patch tested?
Existing tests, which cover
regexp_extract,regexp_extract_all, andregexp_instr:All 24 tests pass.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Isaac
This pull request and its description were written by Isaac.