Get the latest tech news

SIMD within a register: How I doubled hash table lookup performance


It started with a simple thought: four bytes in a hash table bucket look just like an integer. Luckily, this one idea led to a deep dive into bit-twiddling and a 2x performance boost.

To keep the rest of the code clean, all table logic lives in its own class, whose heart is a pre-allocated byte array: So no, nothing breaks, the algorithm is still robust: HasZero only gives a positive result if a zero byte exists after the XOR, which only happens if our target fingerprint was in the bucket to begin with. I’m still not a huge fan of stuffing dense bit tricks into production C#—they can be hard to read and even harder to maintain if something goes wrong.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Register

Register

Photo of SIMD

SIMD

Related news:

News photo

SIMD.info – Reference tool for C intrinsics of all major SIMD engines

News photo

The messy reality of SIMD (vector) functions

News photo

Finding a billion factorials in 60 ms with SIMD