Skip to content

Speed up core logic using Rust#31

Merged
sgoodm merged 8 commits intosgoodm:masterfrom
jacobwhall:master
Apr 20, 2026
Merged

Speed up core logic using Rust#31
sgoodm merged 8 commits intosgoodm:masterfrom
jacobwhall:master

Conversation

@jacobwhall
Copy link
Copy Markdown
Contributor

This PR rewrites some of the core distance calculations in Rust, using crates such as kiddo (k-d trees) and rayon (parallelization) to faithfully re-implement this logic. The result is a drop-in replacement for the original, passing all tests and running significantly faster.

A few notes:

  • I have used uv for dependency management and to run CI tests
  • Maturin handles cross-platform compilation for package distribution
  • Since I was already working in pyproject.toml, I went ahead and bumped the version to 0.4.0

I recommend releasing something like 0.4.0-alpha to ensure the package distributes correctly, and give end users the chance to test this package in their environments before making a full 0.4.0 release.

@jacobwhall
Copy link
Copy Markdown
Contributor Author

I removed the progress_bar option, since it will need a reimplementation in Rust.

@jacobwhall
Copy link
Copy Markdown
Contributor Author

Quick before/after benchmark:

Before:

Benchmark 1: uv run examples/simple_example.py
  Time (mean ± σ):      1.139 s ±  0.016 s    [User: 4.539 s, System: 0.093 s]
  Range (min … max):    1.116 s …  1.165 s    10 runs

After:

Benchmark 1: uv run examples/simple_example.py
  Time (mean ± σ):     199.9 ms ±   9.0 ms    [User: 1930.3 ms, System: 65.0 ms]
  Range (min … max):   186.7 ms … 215.1 ms    14 runs

Please take this with a grain of salt since benchmarks often struggle to represent real-world situations, and my computer might perform differently than yours.

@sgoodm sgoodm merged commit 9c1c32c into sgoodm:master Apr 20, 2026
6 checks passed
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