Skip to content

Add ZSTD_HASH_USE_CRC32C to use an optimized hash#4611

Open
danlark1 wants to merge 4 commits intofacebook:devfrom
danlark1:dev
Open

Add ZSTD_HASH_USE_CRC32C to use an optimized hash#4611
danlark1 wants to merge 4 commits intofacebook:devfrom
danlark1:dev

Conversation

@danlark1
Copy link
Contributor

@danlark1 danlark1 commented Mar 6, 2026

At Google we found 3-5% improvement for densely
compressed data when using CRC32C and low bits
of its hash.

Most uplift should be seen with at least -msse4.2 flag
for x86-64 and march=armv8-a+crc extension
(from Arm8.3 CRC is mandatory).

In this patch we added a macro, fixed implementation
details which relied on shifts and added CI tests with
different configurations. We also added a crc32c
regression test to compare sizes and verify it's not
regressing the values too much.

At Google we found 3-5% improvement for densely
compressed data when using CRC32C and low bits
of its hash.

Most uplift should be seen with at least `-msse4.2`
flag for x86-64 and march=armv8-a+crc extension
(from Arm8.3 CRC is mandatory).

In this patch we added a macro, fixed
implementation details which relied on shifts
and added CI tests with different configurations.
We also added a crc32c regression test to compare
sizes and verify it's not regressing the values too
much.
@meta-cla meta-cla bot added the CLA Signed label Mar 6, 2026
@terrelln
Copy link
Contributor

Everything looks reasonable to me! I'm going to spend some time testing this internally, and will get back to you.

To fix the determinism test, you just need to add ZSTD_HASH_USE_CRC32C to this check:

/**
* ZSTD_IS_DETERMINISTIC_BUILD must be set to 0 if any compilation macro is
* active that impacts the compressed output.
*
* NOTE: ZSTD_MULTITHREAD is allowed to be set or unset.
*/
#if defined(ZSTD_CLEVEL_DEFAULT) \
|| defined(ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR) \
|| defined(ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR)
# define ZSTD_IS_DETERMINISTIC_BUILD 0
#else
# define ZSTD_IS_DETERMINISTIC_BUILD 1
#endif

That will opt the build out of the determinism test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants