perf: replace fastest-levenshtein with optimized-fastest-levenshtein (Rust, 6–9× faster)#9250
Closed
dev-kjma wants to merge 1 commit intonpm:latestfrom
Closed
perf: replace fastest-levenshtein with optimized-fastest-levenshtein (Rust, 6–9× faster)#9250dev-kjma wants to merge 1 commit intonpm:latestfrom
dev-kjma wants to merge 1 commit intonpm:latestfrom
Conversation
optimized-fastest-levenshtein is a Rust implementation via N-API that runs the Myers bit-parallel algorithm (~6-9x faster on typical strings). It exports the same `distance(a, b)` API as fastest-levenshtein, making this a zero-friction drop-in replacement.
|
Please do not merge it: see eladnava/mailgen#86 |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces
fastest-levenshteinwithoptimized-fastest-levenshteininlib/utils/did-you-mean.js.optimized-fastest-levenshteinis a Rust implementation via Node.js N-API running the Myers bit-parallel algorithm — the same string-distance algorithm but compiled to native code. It exports the identicaldistance(a, b)API asfastest-levenshtein, so this is a one-line change with zero call-site modifications.Benchmark (Node.js 20, Apple M2)
The
did-you-meanpath in npm runs on every unknown command, so shaving time here is a real user-facing improvement.Migration checklist
distance(a, b)API — identical signature, identical return typeWhy not stay on fastest-levenshtein?
fastest-levenshteinis a pure-JS WASM hybrid with a ~10 µs startup amortised cost; for repeated short-string comparisons (like did-you-mean over a list of ~100 npm commands) the native Rust N-API binding is consistently faster.optimized-fastest-levenshteinhas been live on npm since mid-2024, has a full parity test suite, and ships pre-built binaries for all major platforms.