Date: 2025-10-29 Objective: Profile, benchmark, and optimize position transition functions across all three Levenshtein algorithms Status: ⏳ In Progress - Benchmarks Running
Location: benches/transition_benchmarks.rs
Test Matrix:
Environment:
RUSTFLAGS="-C target-cpu=native"cargo flamegraph (attempted - permission issues)| Window Size | Time (ns) | Throughput (Melem/s) | Analysis |
|---|---|---|---|
| window=1 | 13.687 | 73.06 | Optimal |
| window=2 | 13.090 | 152.79 | Optimal |
| window=4 | 14.525 | 275.38 | Optimal |
| window=8 | 17.009 | 470.34 | Optimal |
Finding: characteristic_vector is extremely fast (13-17ns). Stack-allocated buffer works perfectly. Conclusion: ✅ No optimization needed - already optimal
| Pattern | Time (ns) | Analysis |
|---|---|---|
| immediate | 1.374 | Best case - immediate match found |
| middle | 1.736 | 2 iterations to find match |
| end | 1.920 | 3 iterations to find match |
| no_match | 1.919 | Full scan - same as end |
Finding: index_of_match is sub-2ns - phenomenal early-exit optimization. Conclusion: ✅ No optimization needed - already optimal
| Scenario | max_distance | Time (ns) | Analysis |
|---|---|---|---|
| match | d=1 | 14.921 | Immediate match - fast path |
| no_match | d=1 | 15.580 | Worst case - full scan |
| delayed_match | d=1 | 15.300 | Middle case |
| match | d=2 | 14.642 | Fast path maintained |
| no_match | d=2 | 17.596 | Slightly slower with more deletions |
| delayed_match | d=2 | 15.412 | Consistent |
| match | d=3 | 14.378 | Fast path |
| no_match | d=3 | 15.423 | Reasonable |
Observations:
Preliminary Conclusion: Position transitions are already highly optimized.
Still waiting for:
transition_transposition benchmarkstransition_merge_split benchmarkstransition_state (full state transition)transition_by_state_size (scaling analysis)prefix_mode comparisonalgorithm_comparison head-to-headposition_allocation SmallVec analysisBased on early results, these seem UNLIKELY to need optimization:
Epsilon Closure
State Transition Overhead
transition_state() not yet benchmarkedAlgorithm Comparison
| Operation | Theoretical | Measured | Status |
|---|---|---|---|
| characteristic_vector | O(k), k≤8 | 13-17ns | ✅ Matches |
| index_of_match | O(k), k≤4 | 1.4-1.9ns | ✅ Matches |
| transition_standard | O(k) | 14-18ns | ✅ Matches |
| transition_state | O(n×k×m) | ⏳ Pending | - |
| epsilon_closure | O(n×m) | ⏳ Pending | - |
Where:
File: src/transducer/transition.rs
characteristic_vector() - lines 22-36
index_of_match() - lines 105-112
transition_standard() - lines 123-192
transition_transposition() - lines 198-323
transition_merge_split() - lines 330-426
epsilon_closure_mut() - lines 433-465
transition_state() - lines 509-551
transition_state_pooled() - lines 580-638
python3 analyze_transition_results.pyIF all transition functions are <50ns:
IF state transition (transition_state) is >1µs:
IF algorithm comparison shows >2x difference:
Based on micro-benchmark results, the low-level primitive functions are already highly optimized:
This suggests that, like the subsumption optimization analysis, we may find that the current implementation is already optimal or very close to optimal.
The key question is: What is the performance of full state transitions?
If transition_state() is fast (e.g., <200ns for typical 3-position states), then there's likely nothing to optimize. The next bottleneck would be elsewhere in the system (dictionary traversal, result collection, etc.).
[[bench]]
name = "transition_benchmarks"
harness = false
src/transducer/transition.rssrc/transducer/state.rssrc/transducer/position.rsSUBSUMPTION_OPTIMIZATION_REPORT.mdReport Status: 🔄 Live Document - Updating as benchmarks complete Last Updated: 2025-10-29 04:57 UTC
Current Progress:
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |