Speeding up small Ruby hashes with SWAR search
Speeding Up (Small) Ruby Hashes
Ruby's Hash class uses a linear array for up to 8 entries, making lookups O(n). A new technique applies SWAR (SIMD within a register) to search all 8 hint bytes at once, achieving O(1) lookups. Benchmarks show the 8th key lookup is 1.58x slower than the first, but SWAR could close that gap.
But what if ar_table lookups could be made O(1) too?