Skip to content

perf: optimize spark_regexp_extract#4894

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/spark_regexp_extract-datafusion-comet-20260711-073621
Open

perf: optimize spark_regexp_extract#4894
andygrove wants to merge 1 commit 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 ?

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.

2 participants