-
Notifications
You must be signed in to change notification settings - Fork 209
Use 'crc-fast' crate for better CRC performance #4111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'crc-fast' crate for better CRC performance #4111
Conversation
Replaces crc64fast-nvme with the new crc-fast crate.
Provides a massive performance improvement on modern hardware (>100GiB/s, depending on the platform). Also reduces the package dependencies, since crc-fast provides accelerated calculation for all 3 supported CRC checksums.
Based on the PR template, Contributing Guidelines, and reviewing some other open PRs, it wasn't obvious to me what I should do with a possible Also not clear how some of the other The remaining untouched lock files which reference the older packages are:
Tagging @landonxjames since we've worked on checksums for this project in the past. |
Thanks for the contribution! Massaged a few things that were impacting CI (version bump in aws-smithy-checksums crate, updated the Cargo.lock files with I think all that remains would be the failures on our exotic platform tests. I suspect those probably require a software-only fallback implementation for platforms that don't support any of the expected intrinsics: error: Unsupported architecture for SIMD CRC calculation
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:75:9
|
75 | compile_error!("Unsupported architecture for SIMD CRC calculation");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Unsupported architecture for SIMD CRC calculation
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:91:5
|
91 | compile_error!("Unsupported architecture for SIMD CRC calculation");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused import: `crate::algorithm`
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:8:5
|
8 | use crate::algorithm;
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused imports: `Width32` and `Width64`
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:9:33
|
9 | use crate::structs::{CrcParams, Width32, Width64};
| ^^^^^^^ ^^^^^^^
error[E0308]: mismatched types
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:74:5
|
74 | / {
75 | | compile_error!("Unsupported architecture for SIMD CRC calculation");
76 | | }
| |_____^ expected `u64`, found `()`
error[E0308]: mismatched types
--> /cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.1.0/src/arch/mod.rs:79:24
|
79 | pub fn get_target() -> String {
| ---------- ^^^^^^ expected `String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
For more information about this error, try `rustc --explain E0308`.
warning: `crc-fast` (lib) generated 2 warnings
error: could not compile `crc-fast` (lib) due to 4 previous errors; 2 warnings emitte |
Great, thanks for the info. Is it easiest if I include a software fallback in the in It's possible the POWER8 |
I think that would be best for us. Although both of our exotic platform tests are for I'll take a look at those two other failing CI checks in the coming days, they seem to be hitting some weird versioning stuff unrelated to your change. |
Uses the `crc` crate to provide a table-based software fallback for architectures which don’t support hardware acceleration.
@landonxjames Ok, I added a software fallback in |
Add some flags/transitive dep features to webassembly tests to get getrandom crate to compile. Note there are still some issues getting crc-fast crate to compile for wasm due to use of the libc crate
Cleaned up most of the CI issues and it looks like there is still one problem compiling the https://github.com/smithy-lang/smithy-rs/actions/runs/14936949828/job/41969146796?pr=4111 error[E0412]: cannot find type `c_char` in crate `libc`
--> /opt/cargo/registry/src/index.crates.io-6f17d22bba15001f/crc-fast-1.2.0/src/ffi.rs:240:58
|
240 | pub extern "C" fn crc_fast_get_version() -> *const libc::c_char {
| ^^^^^^ not found in `libc`
|
help: consider importing one of these type aliases
|
8 + use std::ffi::c_char;
|
8 + use std::os::raw::c_char;
|
8 + use core::ffi::c_char;
|
help: if you import `c_char`, refer to it directly
|
240 - pub extern "C" fn crc_fast_get_version() -> *const libc::c_char {
240 + pub extern "C" fn crc_fast_get_version() -> *const c_char {
| |
…to use-crc-fast-crate
@landonxjames Ok, I fixed the |
All the CI is passing so this looks good (that Semver failure always happens for external contributions that make changes to things included in our build image). Running the Canary against this PR as a final check: https://github.com/smithy-lang/smithy-rs/actions/runs/14978881530 |
Merged, thanks for the contribution! (To anyone from the future looking at this, I had to override and merge from the CI account because of the previously mentioned and expected Semver failure) |
While this looks like a great improvement, there is an issue with the use of the In short, that breaks cross-compilation, where binaries built on a machine may not work on a different machine that has the same architecture but a different set of instructions. |
@landonxjames I'm uncomfortable that:
Best case scenario, it's immature and therefore has its share of bugs. See the awslabs/aws-lambda-rust-runtime#993 and awslabs/aws-sdk-rust#1291, which includes the program being killed with "Illegal Instruction". Worse case scenario (albeit unlikely - and I do not claim that this is the case), the dependency is malicious and contains security backdoors (see https://www.reddit.com/r/sysadmin/comments/1bqu3zx/backdoor_in_upstream_xzliblzma_leading_to_ssh/). I would vote for rolling back this PR, and reconsider |
Alternatively, experimental dependencies should be behind opt-in feature flags |
Hi @GPSnoopy, I understand your concern, and we regret the regression this has caused, but some of those claims are inaccurate.
The author was also the author of the crc64fast-nvme we were using previously. We have worked with them before and they are a trusted partner.
The implementation and performance was reviewed and benchmarked extensively internally (including by principal engineers with expertise in high performance checksum implementations)
We are aware of this and chose to take the dependency anyway after discussion with the author, careful review of the code, and consideration for lowering our total number of dependencies.
We are aware of this issue and working to figure out a fix. |
Hi @landonxjames. Thanks for clarifying and giving more context. 👍 |
Motivation and Context
The crc-fast crate provides better performance (>100GiB/s for CRC32 and CRC32C) and a unified solution for calculating CRC32, CRC32C, and CRC64NVME, the three supported CRC checksums.
Description
Replaces the current three separate implementations with a single implementation.
Testing
Drop-in minimal change, existing test coverage is comprehensive and still passes.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.