-
Notifications
You must be signed in to change notification settings - Fork 222
Improved performance of bitmap::from_trusted
(3x)
#578
Conversation
Codecov Report
@@ Coverage Diff @@
## main #578 +/- ##
==========================================
+ Coverage 78.88% 78.90% +0.02%
==========================================
Files 395 395
Lines 24678 24713 +35
==========================================
+ Hits 19467 19500 +33
- Misses 5211 5213 +2
Continue to review full report at Codecov.
|
bitmap::from_trusted
(5x)bitmap::from_trusted
bitmap::from_trusted
bitmap::from_trusted
(2x)
Yeah buddy! 🚀 |
1c8b55d
to
c9f5e9c
Compare
bitmap::from_trusted
(2x)bitmap::from_trusted
(3x)
Optimized it a bit more (to 3x in total) by using chunks of 64 bits instead of chunks of 8. A tinny bit more complex, but 33% is worth imo. 🚀 |
unsafe fn get_byte_unchecked(len: usize, iterator: &mut impl Iterator<Item = bool>) -> u8 { | ||
let mut byte_accum: u8 = 0; | ||
let mut mask: u8 = 1; | ||
for _ in 0..len { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this could be improved by chunking the iterator, and doing something like:
chunk.iter()
.enumerate()
.for_each(|(i, b)| {
*byte |= if b { 1 << i } else { 0 };
});
At least for the binary comparison code, this was leading to great, unrolled, code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't chunking only available in slices, e.g. &[bool].chunk_exact
(or in bitmaps, via u8
chunks)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are right. There might be some remaining optimizations possible, let me take a look :)
Optimizes the creation and extending of
MutableBitmap
. It mostly re-arranges the code to leverage bitmap operations and the trustedLen invariant inside the hot loop.