Skip to content
Myr

Skip all-zero passes in radix sort of results

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

Precompute OR of all sort keys; a byte position that is zero across every key contributes a no-op pass. Default two-criteria setup leaves the low 32 bits zero, so 4 of 8 passes are skipped without a histogram scan. 2x on the sort, 3-8% on high-match queries. No regression when all bytes are used.

authored by Junegunn Choi · committed by Junegunn Choi · parent 2209a94 · Browse files · 2 files+14 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

2 files+14 added−1 removed

  • other:+14 added−1 removed

2 files+14 added−1 removed

modified:src/result.go+12 added
367 unmodified lines
368 buf := scratch[:n]369 src, dst := a, buf370 scattered := 0371372 // OR of all keys: a byte position that is zero here is zero in every key,373 // so its pass is a no-op and can be skipped without a histogram scan.374 // With the common two-criteria setup the low 32 bits are always zero.375 var keyOR uint64376 for i := range src {377 keyOR |= sortKey(&src[i])378 }379380 for pass := range 8 {381 shift := uint(pass) * 8382383 if byte(keyOR>>shift) == 0 {384 continue385 }386387 var count [256]int388 for i := range src {389 count[byte(sortKey(&src[i])>>shift)]++390 }
46 unmodified lines
modified:CHANGELOG.md+2 added-1 removed
1 unmodified line
2=========340.74.25------6- Up to 2x faster matching for single-character queries6- Single-character queries are up to 2.4x faster7 - This is the most latency-sensitive case; the first keystroke scans the entire list before the result cache can help8- Faster sorting of search results; the default two-criteria ranking skips redundant radix passes9- Fixed nondeterministic match highlight positions10- fzf now detects terminal resize on Windows in `--height` mode (#4790) (@Cyrus580529)11- Fixed signal handler cleanup when fzf is used as a library; SIGINT/SIGTERM/SIGHUP and resize handlers no longer persist after `Run()` returns12- fish: fixed history command being affected by user initialization scripts, and improved timestamp colors in CTRL-R (#4862) (@bitraid)
3395 unmodified lines