Improve Snappy CRC32 with crc-fast - #660
Conversation
Replace the optional crc32fast dependency with crc-fast 1.10.0 and use its CRC-32/ISO-HDLC helper for Snappy block checksums. This keeps the Avro trailer format unchanged while allowing the checksum path to use crc-fast's SIMD-backed implementation. Bump the workspace and CI MSRV to 1.89.0 because crc-fast 1.10.0 requires Rust 1.89. Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
|
Do you actually measure a difference when decoding or encoding Avro files? |
Add a Criterion benchmark that compares crc32fast and crc-fast for raw CRC-32/ISO-HDLC, Snappy compression plus CRC, and Snappy decompression plus CRC verification. Document local aarch64 and remote x86_64 benchmark results, including the relevant SIMD instruction-set differences and the remaining MSRV caveat. Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
|
Yes. I added a dedicated benchmark for this in It now measures three paths on both aarch64 and x86_64:
The results are documented in The SIMD detail is architecture-specific: on aarch64 the improvement comes from |
The benchmark was useful for comparison between `crc32fast` and `crc-fast` but we're not going to run those benchmarks again.
Kriskras99
left a comment
There was a problem hiding this comment.
Thank you for providing a benchmark! I still think you won't see much of a performance difference because the Avro encoder/decoder will be the limiting factor (unless your sending Avro objects with large bytes/string).
I have removed the benchmark in a new commit, so it will still be available in the Git history. The benchmark is good, but something we are going to use only once.
If @martin-g agrees with the MSRV bump from 1.88 to 1.89 this can be merged
Summary
crc32fastdependency withcrc-fast1.10.0crc_fast::crc32_iso_hdlc(...)for Avro Snappy block CRC32 calculationavro/benches/crc32_snappy.rsto comparecrc32fastandcrc-fastacross raw CRC, Snappy compression + CRC, and Snappy decompression + CRCavro/benches/crc32_snappy_results.mdcrc-fast1.10.0 requires Rust 1.89Closes #659.
Rationale
The Snappy codec only needs CRC32 over contiguous decoded/uncompressed blocks, so
crc-fast's specialized one-shotcrc32_iso_hdlchelper fits the existing call sites directly. The algorithm remains CRC-32/ISO-HDLC, and the new test locks the public Avro trailer format to the standardb"123456789" -> 0xcbf43926check value encoded as big-endian bytes.The benchmark now covers both isolated CRC cost and Snappy-shaped encode/decode cost. On local aarch64, Snappy compression + CRC improved up to 1.58x and decompression + CRC up to 2.29x. On the x86_64 EPYC test host, Snappy compression + CRC improved up to 4.32x and decompression + CRC up to 3.72x.
The SIMD reason is architecture-specific. On aarch64,
crc-fastcan use PMULL/AES folding, with SHA3/EOR3-assisted variants when available. On x86_64, SSE4.2 CRC32 is CRC32C/ISCSI rather than CRC-32/ISO-HDLC, so the relevant acceleration for this Avro checksum is PCLMULQDQ / VPCLMULQDQ carry-less multiply.crc-fastis configured withdefault-features = false, features = ["std"]to avoid its defaultffi/panic-handlerfeatures while retaining std-backed runtime SIMD detection.Testing
cargo check -p apache-avro --features snappycargo test -p apache-avro --features snappy,derive snappycargo fmt --all --checkcargo build --all-features --all-targetscargo check -p apache-avro --target aarch64-unknown-linux-gnu --features snappycargo bench -p apache-avro --bench crc32_snappy --features snappy,derive --no-runcargo bench -p apache-avro --bench crc32_snappy --features snappy,deriveon local aarch64cargo bench -p apache-avro --bench crc32_snappy --features snappy,deriveonazure-4074205200x86_64Not completed locally:
wasm32-unknown-unknownCI target validation. Installing the target locally stalled while downloadingrust-std, so this should still be watched in CI.