Skip to content

Performance

LocalLens includes optional Rust extensions that accelerate the performance-critical hot paths. The Rust extensions ship as a separate package (locallens-core) built with maturin and PyO3. Install via pip install "locallens[fast]".

Rust-accelerated modules

ModuleWhat it doesSpeedup
BM25Keyword search index build and query1.3x build, 3.2x search
ChunkerStructure-aware text chunking (markdown, code, paragraphs)Parallel batch processing via rayon
WalkerFile discovery + parallel SHA-256 hashing2-3x (parallel hashing)
WatcherFile system change detectionOS-native APIs (FSEvents, inotify)

Checking Rust status

Run locallens doctor to see whether the Rust extensions are active:

┌──────────────────────────────────────────────────────────────────────┐
│                          LocalLens Doctor                            │
├─────────────────┬────────┬───────────────────────────────────────────┤
│ Rust Extensions │   ✓    │ Active: BM25, Chunker, Walker, Watcher   │
└─────────────────┴────────┴───────────────────────────────────────────┘

If the row shows "Not available (pure-Python fallback)", the Rust extension was not compiled. This happens when installing from sdist without a Rust toolchain.

Benchmark results

Measured on synthetic corpora with mock embeddings (scripts/bench_pipeline.py).

BM25: algorithm fix + Rust (200 files, 1,485 chunks)

StageOriginalPython fixRustvs Original
BM25 incremental10,520 ms54 ms42 ms250x
BM25 search (14 queries)27 ms8 ms2.9 ms9x

File walker (500 files)

StagePythonRustSpeedup
Walk + hash146 ms52 ms2.8x

End-to-end indexing

ScaleTimeNotes
200 files0.27 sMock embeddings
500 files0.44 sMock embeddings
50k files69 sMock embeddings, all stages linear

Real embedding time (sentence-transformers on CPU) adds 2-20 seconds depending on corpus size and hardware. The Rust modules accelerate everything around the embedding step.

Running benchmarks yourself

bash
# Quick smoke test
make bench

# Or directly
python scripts/bench_pipeline.py --files 200 --mock-embed

# Scaling check
python scripts/bench_pipeline.py --files 500 --mock-embed --skip-store

# Full run with real embeddings
python scripts/bench_pipeline.py --files 200

Results are saved as JSON with --out report.json. Detailed findings are in bench-results/FINDINGS.md.

Fallback behavior

If the Rust extension is not available, LocalLens uses the pure-Python implementations transparently. Same API, same results, just slower on large corpora. The fallback is automatic and requires no configuration.

Building from source

The Rust extension requires a Rust toolchain (1.80+):

bash
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build and install the Rust extensions
cd rust && maturin develop --release

# Verify
python -c "from locallens._internals._rust import HAS_RUST; print(HAS_RUST)"

Pre-built wheels for Linux, macOS (x86_64 + ARM), and Windows are published to PyPI on each release as the locallens-core package.

Released under the MIT License.