From f38ca3a10db883cd00da421bf0dc012ab5d576da Mon Sep 17 00:00:00 2001 From: Loric ANDRE Date: Thu, 26 Feb 2026 15:05:28 +0100 Subject: [PATCH] perf(skim_v3): tighten typo-mode upper band bound in typo_vband_row Previously the upper column bound in typo mode was always m (the full choice length), even for early rows where the diagonal sits far from the right edge. Compute hi = (j + bandwidth).min(m) symmetrically with the existing lower bound, skipping cells that cannot contribute to a valid alignment and reducing work for short patterns on long strings. --- src/fuzzy_matcher/skim_v3.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fuzzy_matcher/skim_v3.rs b/src/fuzzy_matcher/skim_v3.rs index e1fb64e6..26121e15 100644 --- a/src/fuzzy_matcher/skim_v3.rs +++ b/src/fuzzy_matcher/skim_v3.rs @@ -766,13 +766,17 @@ fn find_first_char(pat: &[C], cho: &[C], respect_case: bool) -> Option< /// Row-major V-shaped band: compute column bounds at row `i`. /// -/// The result is an upper triangle starting at the diagonal (j ~ i + j_first - 1) +/// The band is a symmetric window of width `bandwidth` around the main +/// diagonal `j ≈ i + j_first - 1`. Both lower and upper bounds are clamped +/// to `[1, m]`. Tightening the upper bound (previously always `m`) avoids +/// computing cells in the right half of the matrix for early rows. #[inline(always)] fn typo_vband_row(i: usize, m: usize, bandwidth: usize, j_first: usize) -> (usize, usize) { let j = i + j_first - 1; let lo = j.saturating_sub(bandwidth).max(1); + let hi = (j + bandwidth).min(m); - (lo, m) + (lo, hi) } // ---------------------------------------------------------------------------