Skip to content

perf: replace fastest-levenshtein with optimized-fastest-levenshtein (Rust, 6–9× faster on string comparison)#43855

Open
dev-kjma wants to merge 1 commit intogithub:mainfrom
dev-kjma:perf/swap-fastest-levenshtein-for-native-rust
Open

perf: replace fastest-levenshtein with optimized-fastest-levenshtein (Rust, 6–9× faster on string comparison)#43855
dev-kjma wants to merge 1 commit intogithub:mainfrom
dev-kjma:perf/swap-fastest-levenshtein-for-native-rust

Conversation

@dev-kjma
Copy link
Copy Markdown

What this does

Replaces fastest-levenshtein with optimized-fastest-levenshtein — a full drop-in replacement implemented in Rust via N-API.

The import is updated to use the aliased distance/closest exports so zero call-site changes are needed elsewhere.

Benchmark results (Apple M2, Node.js v25.2.1, mitata)

Input size fastest-levenshtein (JS) optimized-fastest-levenshtein (Rust) Speedup
Medium strings (35–45 chars) 1,750 ns 1,320 ns 1.33× faster
Long strings (~810 chars) 342 µs 55 µs 6.2× faster
Very long strings (~700 chars) 1,280 µs 138 µs 9.3× faster

The algorithm complexity drops from O(n × m) to O(n × ⌈m/64⌉) — processing 64 DP columns per CPU instruction using bitwise arithmetic. The benefit grows with string length.

Why it's safe

  • 139 parity tests verify bit-for-bit identical output vs fast-levenshtein (same underlying Myers algorithm)
  • Exports get(a,b), distance(a,b) (alias), and closest(str, arr) — complete fastest-levenshtein API parity
  • Zero production dependencies — links only against Node's built-in N-API
  • 8 releases since v1.0.0 (Aug 2024), MIT license

Source: https://github.com/dev-kjma/faster-levenshtein · https://www.npmjs.com/package/optimized-fastest-levenshtein

@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey there spelunker. It looks like you've modified some files that we can't accept as contributions:

  • package.json
  • src/content-render/unified/rewrite-local-links.ts

You'll need to revert all of the files you changed that match that list using GitHub Desktop or git checkout origin/main <file name>. Once you get those files reverted, we can continue with the review process. :octocat:

The complete list of files we can't accept are:

  • .devcontainer/**
  • .github/**
  • data/reusables/rai/**
  • Dockerfile*
  • src/**
  • package*.json
  • content/actions/how-tos/security-for-github-actions/security-hardening-your-deployments/**

We also can't accept contributions to files in the content directory with frontmatter contentType: rai.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

How to review these changes 👓

Thank you for your contribution. To review these changes, choose one of the following options:

A Hubber will need to deploy your changes internally to review.

Table of review links

Note: Please update the URL for your staging server or codespace.

This pull request contains code changes, so we will not generate a table of review links.

🤖 This comment is automatically generated.

@gallowaymgn-png
Copy link
Copy Markdown

What this does

Replaces fastest-levenshtein with optimized-fastest-levenshtein — a full drop-in replacement implemented in Rust via N-API.

The import is updated to use the aliased distance/closest exports so zero call-site changes are needed elsewhere.

Benchmark results (Apple M2, Node.js v25.2.1, mitata)

Input size fastest-levenshtein (JS) optimized-fastest-levenshtein (Rust) Speedup
Medium strings (35–45 chars) 1,750 ns 1,320 ns 1.33× faster
Long strings (~810 chars) 342 µs 55 µs 6.2× faster
Very long strings (~700 chars) 1,280 µs 138 µs 9.3× faster
The algorithm complexity drops from O(n × m) to O(n × ⌈m/64⌉) — processing 64 DP columns per CPU instruction using bitwise arithmetic. The benefit grows with string length.

Why it's safe

  • 139 parity tests verify bit-for-bit identical output vs fast-levenshtein (same underlying Myers algorithm)
  • Exports get(a,b), distance(a,b) (alias), and closest(str, arr) — complete fastest-levenshtein API parity
  • Zero production dependencies — links only against Node's built-in N-API
  • 8 releases since v1.0.0 (Aug 2024), MIT license

Source: https://github.com/dev-kjma/faster-levenshtein · https://www.npmjs.com/package/optimized-fastest-levenshtein.patch

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

Labels

triage Do not begin working on this issue until triaged by the team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants