-
Notifications
You must be signed in to change notification settings - Fork 763
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency fileenhancementNew feature or requestNew feature or request
Description
Unify CRC Implementation - Replace with crc-fast
Problem Description
The project currently uses multiple different CRC calculation libraries:
crc-fast = "1.6.0"crc32c = "0.6.8"crc32fast = "1.5.0"crc64fast-nvme = "1.2.1"
This multi-library approach causes:
- Code redundancy - Multiple implementations of the same functionality
- Maintenance complexity - Need to familiarize with multiple library APIs
- Performance inconsistency - Different libraries may have performance variations
- Dependency bloat - Increases final binary size
Goal
Migrate all CRC calculations to use the crc-fast library exclusively and remove dependencies on other CRC libraries.
Migration Requirements
1. Dependency Management
# Remove
crc32c = "0.6.8"
crc32fast = "1.5.0"
crc64fast-nvme = "1.2.1"
# Keep and potentially upgrade
crc-fast = "1.6.0" # or consider upgrading to latest version2. API Migration Guide
From crc32c
// Original code
use crc32c::crc32c;
let checksum = crc32c(&data);
// New code
use crc_fast::Crc;
let crc = Crc::<u32>::new(&crc_fast::CRC_32_ISCSI); // CRC-32C (ISCSI)
let checksum = crc.calculate(&data);From crc32fast
// Original code
use crc32fast::Hasher;
let mut hasher = Hasher::new();
hasher.update(&data);
let checksum = hasher.finalize();
// New code
use crc_fast::Crc;
let crc = Crc::<u32>::new(&crc_fast::CRC_32_ISO_HDLC);
let checksum = crc.calculate(&data);From crc64fast-nvme
// Original code
use crc64fast_nvme::Crc64;
let checksum = Crc64::new().checksum(&data);
// New code
use crc_fast::Crc;
let crc = Crc::<u64>::new(&crc_fast::CRC_64_ECMA_182);
let checksum = crc.calculate(&data);Implementation Steps
Step 1: Analyze Existing Code Usage
- Use grep to analyze all CRC library usage locations
- Document CRC algorithm types for each usage scenario
- Confirm migration feasibility
Step 2: Create Unified CRC Adapter Layer
- Create unified interface in
src/crc/mod.rs - Implement all required CRC algorithm variants
- Maintain compatibility with original APIs
Step 3: Gradually Replace Calling Code
- First replace
crc32cusage - Then replace
crc32fastusage - Finally replace
crc64fast-nvmeusage - Run tests to verify after each replacement
Step 4: Clean Up Dependencies and Code
- Remove unnecessary dependencies from Cargo.toml
- Remove adapter layer (if no longer needed)
- Run full test suite
Step 5: Performance Verification and Optimization
- Compare performance before and after migration
- Enable crc-fast SIMD features
- Conduct stress testing
Acceptance Criteria
- All CRC calculation functions work correctly
- Performance is not worse than original implementation
- All test cases pass
- Code review approved
- Dependency cleanup completed
Risk Control
- Rollback plan: Keep git history of original code for easy rollback if needed
- Phased implementation: Replace gradually to avoid large-scale changes at once
- Performance testing: Compare performance before and after migration
- Compatibility verification: Ensure CRC results match in all usage scenarios
Copilot
Metadata
Metadata
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency fileenhancementNew feature or requestNew feature or request