Live data from Hacker News

The search for a faster CRC32

blog.fastmail.com

21–30 of 53 posts

Re: The search for a faster CRC32

#21
post #20

Modern Intel CPUs have an instruction specifically to compute CRC. This instruction is easily consumed through a C++ intrinsic, literally in one line of code. You can't do any better than that, no matter what you use.

They have lots of data hashed against a different CRC polynomial. The CRC32C acceleration instructions are unsuitable.

Re: The search for a faster CRC32

#22
post #20

Modern Intel CPUs have an instruction specifically to compute CRC. This instruction is easily consumed through a C++ intrinsic, literally in one line of code. You can't do any better than that, no matter what you use.

In this particular case, however:

[Intel's CRC32 CPU instructions] uses different inputs to the CRC32 algorithm (known as the polynomial) which is apparently more robust, and is used in networks, filesystems, that sort of thing. It gives different results to the "standard" polynomial, typically used in compression.

They would have to go back and recompute all their existing stored checksums.

Re: The search for a faster CRC32

#23
If they have CRC accounting for 10% of CPU, they must be using these checksums a lot. At some point I'd imagine the false error rate simply due to bit flips and other random errors on the path from database through CRC function will outlast whatever value you are getting from the constant rechecks.

Also, literature suggests a throughput of ∼2.67 bytes per cycle for the CRC32 instruction, a three fold improvement over best in class non-HW routines. I'm quite sure it would be worth it to reconvert previous checksums if you can do so in a way that minimizes downtime (think TrueCrypt doing a transparent initial encryption; not encrypting when theres IO load).

Re: The search for a faster CRC32

#26
post #20

Modern Intel CPUs have an instruction specifically to compute CRC. This instruction is easily consumed through a C++ intrinsic, literally in one line of code. You can't do any better than that, no matter what you use.

They have lots of data hashed against a different CRC polynomial. The CRC32C acceleration instructions are unsuitable.

They should migrate to crc32c!

Re: The search for a faster CRC32

#27

why not rip out CRC32 and put in xxhash?

Last time I needed really fast hashing I used FNV. How does it compare to xxhash?

Fnv is fast because the code is tiny and hashing a few bytes is fast. xxhash uses multiple parallel streams and has very high throughput. They are fast hashes, each in their end of the spectrum, Fnv for 1-16 byte keys and xxhash for long data. It's better to call xxhash a checksum, since that's its purpose.

Re: The search for a faster CRC32

#28

Earlier quoted context omitted.

Last time I needed really fast hashing I used FNV. How does it compare to xxhash?

Never mind - it's covered in the other reply link here. Looks like xxhash is the goto hash algorithm now.

That's a misunderstanding. If you need a hash or checksum for very long data (megabytes, gigabytes), use xxhash. It's not the best for hash tables.

Re: The search for a faster CRC32

#29
post #28

Earlier quoted context omitted.

Never mind - it's covered in the other reply link here. Looks like xxhash is the goto hash algorithm now.

That's a misunderstanding. If you need a hash or checksum for very long data (megabytes, gigabytes), use xxhash. It's not the best for hash tables.

Good to know. I was using FNV to hash spam signatures which are typically small. Glad I chose well.

Re: The search for a faster CRC32

#30

If they have CRC accounting for 10% of CPU, they must be using these checksums a lot. At some point I'd imagine the false error rate simply due to bit flips and other random errors on the path from database through CRC function will outlast whatever value you are getting from the constant rechecks. Also, literature suggests a throughput of ∼2.67 bytes per cycle for the CRC32 instruction, a three fold improvement over…

Is the CRC32 instruction much faster than an optimized implementation using PCLMULQDQ? It's available on a wider range of CPUs, but I thought I remembered that PCLMULQDQ worked very quickly.
Post reply on HN