-
Notifications
You must be signed in to change notification settings - Fork 48
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
Feature request: make polynomial tables optional #57
Comments
Any thoughts on how to expose this in the public API? Maybe struct Crc<W: Width, U: CrcUpdate<W>> {
pub algorithm: &'static Algorithm<W>,
crc_update: U,
}
trait CrcUpdate<W: Width> {
fn update(&self, crc: W, bytes: &[u8]) -> W;
}
struct Table<W: Width>{
algorithm: &'static Algorithm<W>,
table: [W; 256]
}
impl<W: Width> CrcUpdate<W> for Table<W> {
fn update(&self, crc: W, bytes: &[u8]) -> W {
todo!()
}
} Then, there can be a low-memory usage implementation of |
I played around with @akhilles proposal because I was interested in the opposite direction: making this faster with bigger lookup tables. The only drawback I can see is that it would have to drop a lot of the The table generation is still const, just the update() calls would need to lose the Using the slice-by-16 algorithm for the u32 CRC I am able to achieve a 7x throughput increase with a 16x bigger lookup table (256 * 4 * 16 B = 16kB).
@mrhooray what's your opinion on this? I'd be willing to prepare a PR with these changes but it's a bit of busywork to do this for every width so I'd like an approval before I start doing that. |
Thanks for looking into this - the speedup is impressive and different scenarios could benefit from it. |
Hmm, the perf gains do look promising. I'm wondering if there's a way to configure table size while preserving API compatibility. Maybe using feature flags? |
Ok, so I think it might be possible to support bigger (and smaller) lookup tables while keeping const and not breaking API. I have a proof of concept here: #76. Basically, we can add support for Just need to confirm that switching from |
Oh that's clever! I am not completely sure whether this is a breaking change either. But as long as So for me to move forward I'd wait until #76 is merged (if it works out) and would then make a PR that introduces something like this: struct Slice16U32{}
impl Implementation for Slice16U32 {
....
}
impl Crc<Slice16u32> {
...
} That would be cool and would allow for gradual addition of optimizations for separate widths |
It would be great to be able to omit the allocation of the tables in memory-constrained environments and instead fall back to generating the value for each byte on demand.
The text was updated successfully, but these errors were encountered: