-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix inflate_fast_help
loop bound
#260
Conversation
Codecov ReportAttention: Patch coverage is
|
ad248e5
to
8ed2c63
Compare
@@ -77,6 +77,11 @@ impl<'a> BitReader<'a> { | |||
self.end as usize - self.ptr as usize | |||
} | |||
|
|||
#[inline(always)] | |||
pub fn bytes_remaining_including_buffer(&self) -> usize { | |||
(self.end as usize - self.ptr as usize) + (self.bits_used as usize >> 3) |
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.
Using / 8
instead of >> 3
may be a bit clearer and will optimize to the same assembly.
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.
we can make a pass over the repo at some point. I think zlib-ng never updated this, and the original zlib that it forked was written at a time when apparently that optimization was not (effectively) guaranteed.
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.
Nice!
When you finally spot the thing... 🤦 we are now faster than zlib-ng for all chunk sizes.
It's only a marginal improvement for chunk size 2**4, but quite significant for what are probably the most common chunk sizes (very small chunk sizes likely indicate io-bound operation).
After fixing the bug of exiting the loop too early (first commit), I then made the bound a bit more accurate, and finally refactored the output type of
len_and_friends
. The final commit has no performance impact.