Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Rust faster than C with this one simple trick (optimization for levenshtein) #346

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tp971
Copy link

@tp971 tp971 commented Jan 12, 2025

I have:

Description of changes

Replacing the inclusive ranges 1..=n and 1..=m by exclusive ranges 1..n + 1 and 1..m + 1 in the Rust version of Levenshtein improves the performance by about 25% on my machine (making it about 3% faster than the C version). The reason for that is that the implementation of inclusive ranges accommodates for the fact that the upper bound might be the largest representable integer (e.g. 1..=usize::MAX) by adding additional code that is executed in every iteration of the loop, which might also prevent certain compiler optimizations from running, making the performance even worse.

@zierf
Copy link
Contributor

zierf commented Jan 13, 2025

For me using enumerate on the string bytes instead of exclusive ranges saves ~10%.

see also PR #351

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