david-mollitor-db opened a new pull request, #58815:
URL: https://github.com/apache/spark/pull/58815

   ### What changes were proposed in this pull request?
   
   `RegExpExtractBase.extract`, `RegExpExtractBase.extractAll`, and 
`RegExpInStr` call
   `Matcher.toMatchResult()` on every match, then read 
`groupCount`/`group(idx)` (the extract
   helpers) or `start()` (`regexp_instr`) from the returned snapshot:
   
   ```scala
   if (matcher.find()) {
     val mr = matcher.toMatchResult
     checkGroupIndex(prettyName, mr.groupCount, idx)
     val group = mr.group(idx)
     ...
   }
   ```
   
   `Matcher.toMatchResult()` allocates an immutable `MatchResult` snapshot of 
the current match
   state, including a copy of the groups `int[]`. This PR reads the same values 
directly from the
   `Matcher`:
   
   ```scala
   if (matcher.find()) {
     checkGroupIndex(prettyName, matcher.groupCount, idx)
     val group = matcher.group(idx)
     ...
   }
   ```
   
   and `m.toMatchResult().start()` -> `m.start()` in `RegExpInStr` (both the 
interpreted and the
   codegen paths).
   
   ### Why are the changes needed?
   
   The values are read immediately after `find()`, with nothing else mutating 
the matcher in
   between, so `Matcher.groupCount()`, `Matcher.group(int)`, and 
`Matcher.start()` return exactly
   the same values as the corresponding `MatchResult` methods for the current 
match. Snapshotting
   into a `MatchResult` first only adds one allocation (the snapshot plus a 
copy of the groups
   `int[]`) per match on the `regexp_extract`, `regexp_extract_all`, and 
`regexp_instr` hot paths.
   
   Profiling a `regexp_extract` workload under JFR (`settings=profile`) shows
   `java.util.regex.Matcher.toMatchResult` accounting 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`, and 
`regexp_instr`:
   
   ```
   build/sbt 'catalyst/testOnly *RegexpExpressionsSuite'
   ```
   
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to