Skip to content

perf(lambda-rs-args): Prune candidates shorter than the best levenshtein distance#193

Merged
vmarcella merged 1 commit intomainfrom
vmarcella/optimize-distance-computations
Mar 12, 2026
Merged

perf(lambda-rs-args): Prune candidates shorter than the best levenshtein distance#193
vmarcella merged 1 commit intomainfrom
vmarcella/optimize-distance-computations

Conversation

@vmarcella
Copy link
Member

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)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance (change that improves performance)
  • Test (adding or updating tests)
  • Build/CI (changes to build process or CI configuration)

Affected Crates

  • lambda-rs
  • lambda-rs-platform
  • 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)
  • New code includes appropriate documentation
  • Public API changes are documented
  • Breaking changes are noted in this PR description

Testing

Commands run:

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

  • 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.

@github-actions
Copy link

✅ Coverage Report

📊 View Full HTML Report (download artifact)

Overall Coverage

Metric Value
Total Line Coverage 76.92%
Lines Covered 12700 / 16511

Changed Files in This PR

File Coverage Lines
crates/lambda-rs-args/src/lib.rs 75.94% 767/1010

PR Files Coverage: 75.94% (767/1010 lines)


Generated by cargo-llvm-cov · Latest main coverage

Last updated: 2026-03-12 19:59:30 UTC · Commit: 245dfa1

@vmarcella vmarcella merged commit c38f004 into main Mar 12, 2026
10 checks passed
@vmarcella vmarcella deleted the vmarcella/optimize-distance-computations branch March 12, 2026 20:18
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.

1 participant