Skip to content

perf: optimize regexp_match for literal pattern usage (20% faster)#23547

Open
andygrove wants to merge 5 commits into
apache:mainfrom
andygrove:auto-opt/regexp_match-datafusion-20260713-235232
Open

perf: optimize regexp_match for literal pattern usage (20% faster)#23547
andygrove wants to merge 5 commits into
apache:mainfrom
andygrove:auto-opt/regexp_match-datafusion-20260713-235232

Conversation

@andygrove

@andygrove andygrove commented Jul 14, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize existing expressions

What changes are included in this PR?

Pass a literal regexp pattern/flags to arrow's kernel as scalar Datums so the regex is compiled once per batch, instead of expanding the literal to a full array and forcing a per-row HashMap<String, Regex> cache lookup (plus a per-row format! allocation when flags are present).

Are these changes tested?

Existing tests + new unit tests.

Benchmark (criterion):

  • regexp_match_1000 literal pattern utf8view: 21.394% faster (base 249069ns -> cand 195784ns)
  • regexp_match_1000 pattern array: 2.996% faster (base 190020ns -> cand 184327ns)
  • regexp_match_1000 literal pattern: 23.964% faster (base 261795ns -> cand 199059ns)
  • regexp_match_1000 literal pattern and flags: 37.227% faster (base 280047ns -> cand 175794ns)

Full criterion output:

regexp_match_1000 literal pattern
                        time:   [198.39 µs 198.66 µs 199.03 µs]
                        change: [−24.244% −23.964% −23.600%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
  4 (4.00%) high severe

regexp_match_1000 literal pattern and flags
                        time:   [175.59 µs 175.68 µs 175.81 µs]
                        change: [−37.342% −37.227% −37.124%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

regexp_match_1000 literal pattern utf8view
                        time:   [195.75 µs 195.85 µs 195.98 µs]
                        change: [−21.511% −21.394% −21.298%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

regexp_match_1000 pattern array
                        time:   [184.11 µs 184.22 µs 184.37 µs]
                        change: [−3.1007% −2.9962% −2.8581%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe

Are there any user-facing changes?

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 14, 2026
@andygrove andygrove changed the title perf: optimize regexp_match in datafusion-functions perf: optimize regexp_match (20% faster) Jul 14, 2026
@andygrove andygrove changed the title perf: optimize regexp_match (20% faster) perf: optimize regexp_match for scalar pattern usage (20% faster) Jul 14, 2026
@andygrove andygrove changed the title perf: optimize regexp_match for scalar pattern usage (20% faster) perf: optimize regexp_match for literal pattern usage (20% faster) Jul 14, 2026
@andygrove
andygrove marked this pull request as ready for review July 14, 2026 15:54
@andygrove
andygrove requested review from Jefffrey and comphead July 14, 2026 15:54
Comment thread datafusion/functions/src/regex/regexpmatch.rs

@comphead comphead 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.

Thanks @andygrove

@alamb alamb added the performance Make DataFusion faster label Jul 15, 2026
andygrove and others added 2 commits July 16, 2026 13:47
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.68293% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@3a29d6b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
datafusion/functions/src/regex/regexpmatch.rs 92.68% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23547   +/-   ##
=======================================
  Coverage        ?   80.65%           
=======================================
  Files           ?     1086           
  Lines           ?   366478           
  Branches        ?   366478           
=======================================
  Hits            ?   295583           
  Misses          ?    53272           
  Partials        ?    17623           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation performance Make DataFusion faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants