Speed up batch scans and Python calls - #53
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7b02886-a2c5-43cd-bb97-bfa037d3b625
📊 Benchmark Comparison Results
➖ 41 benchmarks within noise (click to expand)
Legend: ✅ Faster (>5%) · |
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.
Why
For small inputs, the Hamming-distance calculation itself is already extremely fast. Most of the remaining time was being spent around it: setting up Python buffers, checking the selected algorithm repeatedly, or creating too many parallel tasks for batch scans.
This PR removes that avoidable work while preserving the existing API and results.
What changed
bestsearch stops as soon as it finds an exact match, and large scans use four coarse Rayon jobs instead of oversubscribing every CPU.bytesinputs bypass the general buffer protocol, and small generic buffers avoid an unnecessary GIL release/reacquire cycle.Representative results
Measured on an Apple M4 Max using three independent runs:
best, exact match firstbestallbestbest, exact match firstThe single-record Rust kernels are now close to their practical hardware floors. PR #52 builds on this branch to address the remaining measured overhead in array dispatch, generic Python buffers, and concurrency thresholds.
Safety and compatibility
Testing
cargo test --no-default-featurescargo fmt --checkruff check .ruff format --check .python -m pytest -vls .