260301.4 · 5887edc6bae14355a75e73f94bc35fdd24e545a1
Use LSD radix sort for Result sorting in matcher
Replace comparison-based pdqsort with LSD radix sort on the uint64 sort key. Radix sort is O(n) vs O(n log n) and avoids pointer-chasing cache misses in the comparison function. Sort scratch buffer is reused across iterations to reduce GC pressure.
Benchmark (single-threaded, Chromium file list):
- linux query (180K matches): ~16% faster
- src query (high match count): ~31% faster
- Rare matches: equivalent (falls back to pdqsort for n < 128)
reading declarations
Changes to src/result_others.go. All files
@@ -14,3 +14,7 @@ func compareRanks(irank Result, jrank Result, tac bool) bool { } return (irank.item.Index() <= jrank.item.Index()) != tac }++func sortKey(r *Result) uint64 {+ return uint64(r.points[0]) | uint64(r.points[1])<<16 | uint64(r.points[2])<<32 | uint64(r.points[3])<<48+}