Commit c38f004
authored
perf(lambda-rs-args): Prune candidates shorter than the best levenshtein distance (#193)
## Summary
Improve unknown-argument suggestion performance in `lambda-rs-args` by
pruning candidates that cannot beat the current best Levenshtein
distance based on character-length lower bounds.
## Related Issues
N/A
## Changes
- Added an early-prune in `unknown_with_suggestion` to skip Levenshtein
calls when `abs(len(key) - len(arg)) >= best_distance`.
- Kept suggestion output behavior unchanged (`did you mean ...`).
- Added stress coverage with many unrelated flags to validate suggestion
quality under larger candidate sets.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] Feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation (updates to docs, specs, tutorials, or comments)
- [x] Refactor (code change that neither fixes a bug nor adds a feature)
- [x] Performance (change that improves performance)
- [x] Test (adding or updating tests)
- [ ] Build/CI (changes to build process or CI configuration)
## Affected Crates
- [ ] `lambda-rs`
- [ ] `lambda-rs-platform`
- [x] `lambda-rs-args`
- [ ] `lambda-rs-logging`
- [ ] Other:
## Checklist
- [ ] Code follows the repository style guidelines (`cargo +nightly fmt
--all`)
- [ ] Code passes clippy (`cargo clippy --workspace --all-targets -- -D
warnings`)
- [ ] Tests pass (`cargo test --workspace`)
- [x] New code includes appropriate documentation
- [ ] Public API changes are documented
- [ ] Breaking changes are noted in this PR description
## Testing
**Commands run:**
```bash
cargo test -p lambda-rs-args
```
**Manual verification steps (if applicable):**
1. Trigger parse with an unknown flag similar to a known one (e.g.
`--portt` vs `--port`) and verify suggestion output remains correct.
## Screenshots/Recordings
N/A
## Platform Testing
- [x] macOS
- [ ] Windows
- [ ] Linux
## Additional Notes
Asymptotics: worst-case remains `O(A * L^2)` for `A` candidate args and
`L` string length, but the prune reduces expensive Levenshtein
evaluations from `O(A)` to `O(K)` in common cases (`K <= A`) where many
candidates are length-mismatched.1 file changed
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1307 | 1307 | | |
1308 | 1308 | | |
1309 | 1309 | | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
1310 | 1332 | | |
1311 | 1333 | | |
1312 | 1334 | | |
| |||
1512 | 1534 | | |
1513 | 1535 | | |
1514 | 1536 | | |
| 1537 | + | |
1515 | 1538 | | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
1516 | 1547 | | |
1517 | 1548 | | |
1518 | 1549 | | |
| |||
0 commit comments