Date: 2025-11-18 23:45
Optimization: Added can_apply_at() helper to eliminate wasteful allocations in find_first_match()
Changes Made:
can_apply_at() helper function - checks rule applicability without allocatingcan_apply_at_char() for character-level variantfind_first_match() to use can_apply_at() instead of apply_rule_at().is_some()find_first_match_char() similarlyLines Changed: ~50 lines added (helper functions + documentation) Test Results: ✅ All 87 tests passing (0 failures)
| Input Size | Before (ns) | After (ns) | Speedup | % Improvement |
|---|---|---|---|---|
| 5 phones | 1,132 | 823 | 1.38× | 27% faster |
| 10 phones | 2,677 | 1,880 | 1.42× | 30% faster |
| 20 phones | 8,425 | 6,247 | 1.35× | 26% faster |
| 50 phones | 42,997 | 31,346 | 1.37× | 27% faster |
| Input Size | Before (ns/phone) | After (ns/phone) | Improvement |
|---|---|---|---|
| 5 phones | 226 | 165 | 27% faster |
| 10 phones | 268 | 188 | 30% faster |
| 20 phones | 421 | 312 | 26% faster |
| 50 phones | 860 | 627 | 27% faster |
Positive Findings:
Measured Impact:
Degradation Analysis:
Critical Finding: The superlinear scaling pattern remains unchanged!
Ratio Preserved:
Before: 860 / 226 = 3.80×
After: 627 / 165 = 3.80×
This indicates:
Evidence:
find_first_match()Conclusion: Allocation overhead was ~27% of total time, not 284% as initially estimated
H5: Iteration Count Increases with Input Size
Theory: Number of rule applications (iterations) increases superlinearly with input size
Evidence:
apply_rules_seq() complexity: O(iterations × rules × n)Testable Prediction:
Option 1: Profile Iteration Counts
// Add instrumentation to apply_rules_seq()
let mut iteration_count = 0;
loop {
iteration_count += 1;
// ... rest of loop
}
println!("Input size: {}, iterations: {}", s.len(), iteration_count);
Expected Finding:
Option 2: Optimize Pattern Matching
Option 3: Early Termination Heuristics
| Metric | Value | Status |
|---|---|---|
| 50-phone time | 31,346 ns | ✅ Improved |
| Degradation ratio | 3.80× | ⚠️ Unchanged |
| Per-phone (50) | 627 ns | ✅ Better than baseline |
| Metric | Target | Required Improvement |
|---|---|---|
| 50-phone time | ~8,250 ns | 3.80× further speedup |
| Degradation ratio | ~1.0× (linear) | Eliminate superlinear growth |
| Per-phone (50) | ~165 ns | Match 5-phone performance |
Gap Analysis:
Data-Driven Next Step:
Alternative: Accept 27% improvement and move forward
Achieved:
find_first_match()Validated:
Remaining Issue:
Options:
Optimization 1 Complete: ✅ Performance Gain: 27-30% speedup Tests Passing: 87/87 ✅ Further Investigation Required: Yes (H5 - iteration count)
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 |