Skip to content
Myr

Improve search performance by pre-calculating bonus matrix

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

This gives yet another 5% boost.

authored by Junegunn Choi · committed by Junegunn Choi · parent 7ce6452 · Browse files · 1 file+11 added−3 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+11 added−3 removed

  • other:+11 added−3 removed

1 file+11 added−3 removed

modified:src/algo/algo.go+11 added-3 removed
154 unmodified lines
155 initialCharClass charClass = charWhite156157 // A minor optimization that can give 15%+ performance boost158 asciiCharClasses [unicode.MaxASCII + 1]charClass159160 // A minor optimization that can give yet another 5% performance boost161 bonusMatrix [charNumber + 1][charNumber + 1]int16162)163164type charClass int165
42 unmodified lines
208 c = charDelimiter209 }210 asciiCharClasses[i] = c211 }212 for i := 0; i <= int(charNumber); i++ {213 for j := 0; j <= int(charNumber); j++ {214 bonusMatrix[i][j] = bonusFor(charClass(i), charClass(j))215 }216 }217 return true218}219220func posArray(withPos bool, len int) *[]int {
77 unmodified lines
298func bonusAt(input *util.Chars, idx int) int16 {299 if idx == 0 {300 return bonusBoundaryWhite301 }294 return bonusFor(charClassOf(input.Get(idx-1)), charClassOf(input.Get(idx)))302 return bonusMatrix[charClassOf(input.Get(idx-1))][charClassOf(input.Get(idx))]303}304305func normalizeRune(r rune) rune {306 if r < 0x00C0 || r > 0x2184 {
167 unmodified lines
474 }475 Tsub[off] = char476 }477470 bonus := bonusFor(prevClass, class)478 bonus := bonusMatrix[prevClass][class]479 Bsub[off] = bonus480 prevClass = class481482 if char == pchar {
174 unmodified lines
657 if withPos {658 *pos = append(*pos, idx)659 }660 score += scoreMatch653 bonus := bonusFor(prevClass, class)661 bonus := bonusMatrix[prevClass][class]662 if consecutive == 0 {663 firstBonus = bonus664 } else {665 // Break consecutive chunk
299 unmodified lines