Skip to content

perf: optimize levenshtein - #23543

Open
andygrove wants to merge 2 commits into
apache:mainfrom
andygrove:auto-opt/levenshtein-datafusion-20260713-191815
Open

andygrove wants to merge 2 commits into
apache:mainfrom
andygrove:auto-opt/levenshtein-datafusion-20260713-191815

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 expression.

What changes are included in this PR?

Added Myers' bit-parallel Levenshtein fast path for ASCII inputs whose shorter side fits in a 64-bit word, replacing the per-cell character-wise DP with a few bitwise ops per text character.

Are these changes tested?

Existing tests + new unit tests.

Benchmark (criterion):

  • levenshtein_string [size=1024, str_len=32]: 83.81% faster (base 662708ns -> cand 107290ns)
  • levenshtein_string [size=1024, str_len=8]: 54.904% faster (base 58165ns -> cand 26230ns)
  • levenshtein_string [size=4096, str_len=32]: 83.79% faster (base 2640918ns -> cand 428103ns)
  • levenshtein_string [size=4096, str_len=8]: 54.274% faster (base 227761ns -> cand 104146ns)

Full criterion output:

levenshtein size=1024/levenshtein_string [size=1024, str_len=8]
                        time:   [26.188 µs 26.230 µs 26.298 µs]
                        change: [−55.035% −54.904% −54.755%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe
levenshtein size=1024/levenshtein_string [size=1024, str_len=32]
                        time:   [107.24 µs 107.29 µs 107.35 µs]
                        change: [−83.837% −83.810% −83.768%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  2 (20.00%) high mild

levenshtein size=4096/levenshtein_string [size=4096, str_len=8]
                        time:   [104.07 µs 104.15 µs 104.24 µs]
                        change: [−54.330% −54.274% −54.218%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild
levenshtein size=4096/levenshtein_string [size=4096, str_len=32]
                        time:   [427.90 µs 428.10 µs 428.33 µs]
                        change: [−83.799% −83.790% −83.780%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  2 (20.00%) high mild

Are there any user-facing changes?

No

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 14, 2026
@andygrove andygrove changed the title perf: optimize levenshtein in datafusion-functions perf: optimize levenshtein Jul 14, 2026
@andygrove
andygrove marked this pull request as ready for review July 14, 2026 09:15
@andygrove andygrove added the performance Make DataFusion faster label Jul 16, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale PR has not had any activity for some time label Sep 15, 2026
@andygrove
andygrove enabled auto-merge September 16, 2026 20:29
@andygrove
andygrove added this pull request to the merge queue Sep 16, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.93%. Comparing base (140c7c5) to head (7fefc46).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23543   +/-   ##
=======================================
  Coverage   81.93%   81.93%           
=======================================
  Files        1136     1136           
  Lines      429152   429244   +92     
  Branches   429152   429244   +92     
=======================================
+ Hits       351633   351715   +82     
- Misses      56475    56482    +7     
- Partials    21044    21047    +3     

☔ 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.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 16, 2026
@github-actions github-actions Bot removed the Stale PR has not had any activity for some time label Sep 17, 2026
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.

3 participants