News for hackers. Stuff that matters.
Re:New high-quality hash measures 71GB/s on M4 by wpollock on Friday May 16, 2025 @10:43PM (#44011646)
Is rapidhash cache-friendly?
Re:New high-quality hash measures 71GB/s on M4 by wmf on Friday May 16, 2025 @11:24PM (#44011803)
Hash functions don't have any data reuse so none of them are cache-friendly.
Re:New high-quality hash measures 71GB/s on M4 by benwills on Saturday May 17, 2025 @01:46AM (#44012288)
I think they may be asking about the CPU cache.
Re:New high-quality hash measures 71GB/s on M4 by Dylan16807 on Saturday May 17, 2025 @01:48AM (#44012304)
You have to go out of your way to make a hash that doesn't fit into L1, so again they're all basically the same.

You'll probably end up fitting entirely inside the reorder buffer plus a sequential stream from memory, with the actual caches almost irrelevant.

Re:New high-quality hash measures 71GB/s on M4 by benwills on Saturday May 17, 2025 @01:51AM (#44012313)
Sure. Any worthwhile hash function will fit in the instruction cache. But there are ways to make more or less efficient use of the data cache.
Re:New high-quality hash measures 71GB/s on M4 by Dylan16807 on Saturday May 17, 2025 @01:54AM (#44012317)
> Any worthwhile hash function will fit in the instruction cache.

Yes, I'm talking about the data cache.

> But there are ways to make more or less efficient use of the data cache.

How?

You need to touch every byte of input, and nothing should be faster than going right through from start to end.

Re:New high-quality hash measures 71GB/s on M4 by benwills on Saturday May 17, 2025 @02:07AM (#44012347)
I don't know you're experience with hash functions, so you may already know what I'm about to say.

This is a minor example, but since you asked...

https://github.com/Cyan4973/xxHash/blob/dev/xxhash.h#L6432

That's an example of a fair number of accumulators that are stored as XXHash goes through its input buffer.

Many modern hash functions store more state/accumulators than they used to. Previous generations of hash functions would often just have one or two accumulators and run through the data. Many modern hash functions might even store multiple wider SIMD variables for better mixing.

And if you're storing enough state that it doesn't fit in your registers, the CPU will put it into the data cache.

Re:New high-quality hash measures 71GB/s on M4 by Dylan16807 on Saturday May 17, 2025 @02:09AM (#44012357)
> And if you're storing enough state that it doesn't fit in your registers, the CPU will put it into the data cache.

And there's 150+ registers in the actual chip.

But my argument is more that there isn't really an efficient or inefficient way to use L1. So unless you have an enormous amount of state, the question is moot. And if you have so much state you're spilling to L2, that's not when you worry about good or bad cache use, that's a weird bloat problem.

Re:New high-quality hash measures 71GB/s on M4 by Sesse__ on Saturday May 17, 2025 @04:23AM (#44012876)
_Fitting_ in the instruction cache isn't hard, but you'd also ideally let there be room for some other code as well :-) For a hash map lookup, where the hashing is frequently inlined a couple of times, code size matters.
Re:New high-quality hash measures 71GB/s on M4 by Retr0id on Saturday May 17, 2025 @11:17AM (#44014944)
You can have cache-unfriendly hash functions, though.

For example, a common optimisation for CRC implementation involves lookup tables. If your lookup table exceeds L1 then you're going to have a bad time. If your lookup table fits exactly in L1, your benchmarks might look great, while real-world performance suffers (because your other code wants to be making use of L1, too).

I'd imagine rapidhash avoids lookup tables but the question of cache-friendliness is still pertinent.