Skip to content
Myr

Skip dead zones in FuzzyMatchV2 score matrix computation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

In Phase 3 of FuzzyMatchV2, when a cell's left neighbor score is <= 1 and the current character doesn't match the pattern character, the cell's score is guaranteed to be 0 (since gap penalties are -1 and -3). Skip the bonus/gap computation entirely and fast-forward through consecutive non-matching characters in the dead zone. This yields 6-11% faster fuzzy searches on typical workloads.

authored by Junegunn Choi · committed by Junegunn Choi · parent 09ca45f · Browse files · 1 file+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−1 removed

  • other:+21 added−1 removed

1 file+21 added−1 removed

modified:src/algo/algo.go+21 added-1 removed
567 unmodified lines
568 Hsub := H[row+f-f0:][:len(Tsub)]569 Hdiag := H[row+f-f0-1-width:][:len(Tsub)]570 Hleft := H[row+f-f0-1:][:len(Tsub)]571 Hleft[0] = 0572 for off, char := range Tsub {572 for off := 0; off < len(Tsub); off++ {573 char := Tsub[off]574 // When the left neighbor's score is 0 or 1 and the current character575 // doesn't match, the score is guaranteed to be 0 (gap penalties576 // are negative). Skip all the bonus/gap computation.577 if pchar != char && Hleft[off] <= 1 {578 Hsub[off] = 0579 Csub[off] = 0580 // Fast-forward: Hleft of the next cell is the Hsub we just581 // wrote (0), so only a match can break the dead zone.582 off++583 for off < len(Tsub) && Tsub[off] != pchar {584 Hsub[off] = 0585 Csub[off] = 0586 off++587 }588 off--589 inGap = false590 continue591 }592593 col := off + f594 var s1, s2, consecutive int16595596 if inGap {
458 unmodified lines