Static search trees: 40x faster than binary search (2024)
4 hours ago
- #performance-optimization
- #SIMD
- #static-search-tree
- The post implements an optimized static search tree (S+ tree) for high-throughput searching of sorted 32-bit unsigned integers, focusing on throughput measured as queries per second.
- Key optimizations include using SIMD instructions for node searches, batching queries to parallelize memory accesses, prefetching to reduce latency, and pointer arithmetic to streamline operations.
- Tree layouts like S+ trees with branching factor 16 or 17 are explored, with interleaved queries balancing CPU and memory-bound workloads, achieving over 40x speedup from 1150 ns/query to 27 ns/query for 4GB data.
- Prefix partitioning by top bits is tested but adds complexity with limited speed gains, especially on skewed real data like human genome k-mers, making it less practical than interleaved queries.
- Future work suggestions include branchy search for variable iterations, interpolation search to reduce RAM accesses, packing data into 16 bits, supporting range queries, sorting queries for cache reuse, and applying to suffix array searching.