Repository navigation
Conversation
uv test inventory changesThis PR changes the tests when compared with the
|
508b1cb to
7321296
Compare
|
|
||
| /// Calculate the requested hashes of a file. | ||
| async fn hash_file( | ||
| async fn hash_file<const COUNT: usize>( |
There was a problem hiding this comment.
I love const generics.
| )] | ||
| #[serde(transparent)] | ||
| #[rkyv(derive(Debug))] | ||
| pub struct Digest<const BYTES: usize>(SmallString); |
There was a problem hiding this comment.
Note that despite the const generic here, we're still using a SmallString rather than forcing every Digest into a static array. I think this is preferable in terms of stack object size, especially enums.
There was a problem hiding this comment.
You can check the size change with mem::size_of. I think we want a Box<T> here, if the hashes are longer than 8 bytes we're not in the small variant anyway and Option<Box<T>> is 8 byte. This is a code style question though, I don't think it changes perf.
| )] | ||
| #[serde(transparent)] | ||
| #[rkyv(derive(Debug))] | ||
| pub struct Digest<const BYTES: usize>(SmallString); |
There was a problem hiding this comment.
You can check the size change with mem::size_of. I think we want a Box<T> here, if the hashes are longer than 8 bytes we're not in the small variant anyway and Option<Box<T>> is 8 byte. This is a code style question though, I don't think it changes perf.
| } | ||
|
|
||
| /// Encode the exact number of digest bytes as lowercase hexadecimal. | ||
| pub fn from_bytes(bytes: [u8; BYTES]) -> Self { |
There was a problem hiding this comment.
Can't std (with {:x} iirc) do that for us?
There was a problem hiding this comment.
I think so, but we'd either need to switch to a growing String here or pre-allocate and use a fallible write! (not actually fallible, but Never isn't stable yet). I'll look at it though.
There was a problem hiding this comment.
I benched this locally and it's almost 10x slower per-byte, which is surprising to me. I suspect it's because Rust's generic formatter needs to do more booking here.
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]> Fix TODO Signed-off-by: William Woodruff <[email protected]> Remove chum tests Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Summary
WIP, not ready for review.This came from #21131 and me thinking about ways to make more invalid hash states unrepresentable.
TL;DR:
HashDigestis now an enum with size-controlled variants;HashDigestandHashAlgorithmare now both explicit aboutBlake2bbeingBlake2b256Digestwrapper that preserves alphabet/length invariantsTest Plan
Added tests.
The original approach here bumped several cache buckets, but I'm now preserving the original wire layout with
HashDigestWireso that we don't churn on an internal change.This also needs benchmarking.No perf regressions, and microbenchmarks are a lot faster. But hex parsing doesn't really dominate our performance anyways.