Skip to content

perf: optimize spark_regexp_extract#4894

Merged
andygrove merged 2 commits into
apache:mainfrom
andygrove:auto-opt/spark_regexp_extract-datafusion-comet-20260711-073621
Jul 16, 2026
Merged

perf: optimize spark_regexp_extract#4894
andygrove merged 2 commits into
apache:mainfrom
andygrove:auto-opt/spark_regexp_extract-datafusion-comet-20260711-073621

Conversation

@andygrove

@andygrove andygrove commented Jul 11, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize existing expression.

What changes are included in this PR?

Reuse a single CaptureLocations across all rows via captures_read instead of allocating a fresh capture buffer per row with captures(), eliminating one heap allocation per row in the regexp_extract array path.

How are these changes tested?

Existing tests

Benchmark (criterion):

  • spark_regexp_extract_ group 2: 9.362% faster (base 700411ns -> cand 634838ns)
  • spark_regexp_extract_ group 0: 12.413% faster (base 699389ns -> cand 612573ns)
  • spark_regexp_extract_ group 1: 10.116% faster (base 682259ns -> cand 613241ns)

@andygrove
andygrove marked this pull request as ready for review July 11, 2026 13:52
@andygrove andygrove changed the title perf: optimize spark_regexp_extract in datafusion-comet-spark-expr perf: optimize spark_regexp_extract Jul 11, 2026
// Reuse a single set of capture locations across every row. `Regex::captures`
// allocates a fresh location buffer on each call; `captures_read` fills this
// preallocated buffer in place, so the per-row heap allocation is paid only once.
let mut locations = regex.capture_locations();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob we can reuse OptimizedRegex ?

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one LGTM, thanks @andygrove!

@andygrove
andygrove merged commit df01cdd into apache:main Jul 16, 2026
2 checks passed
@andygrove
andygrove deleted the auto-opt/spark_regexp_extract-datafusion-comet-20260711-073621 branch July 16, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants