-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve performance of BinaryNumeralString
#34
Conversation
This allows NumeralStrings to implement the additions and subtractions more efficiently. The Numeral trait is moved into the alloc module as an extension trait on BigUint.
We don't ever want to split a numeral string arbitrarily, so this enables trait implementors to optimise for the precise kind of split that we do need.
Benchmark throughput increases on a Ryzen 9 5950X: - 10 bytes: around 215% - 100 and 1000 bytes: around 375%
We already consume `self` in `BinaryOps::{add_mod_exp, sub_mod_exp}`, and it is guaranteed to have the same byte length as the output, so we can reuse its `Vec<u8>` for the latter.
fixes #11 |
@@ -127,50 +127,46 @@ impl Radix { | |||
} | |||
} |
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.
Suggestion for simpler Radix::from_u32
above this:
fn from_u32(radix: u32) -> Result<Self, InvalidRadix> {
// radix must be in range [2..=2^16]
if !(2..=(1 << 16)).contains(&radix) {
return Err(InvalidRadix(radix));
}
Ok(if radix.count_ones() == 1 {
let log_radix: u32 = 31 - radix.leading_zeros();
Radix::PowerTwo {
radix,
min_len: cmp::max((MIN_RADIX_2_NS_LEN + log_radix - 1) / log_radix, MIN_NS_LEN),
log_radix: u8::try_from(log_radix).unwrap(),
}
} else {
use libm::{ceil, log10};
let min_len = ceil(LOG_10_MIN_NS_DOMAIN_SIZE / log10(f64::from(radix))) as u32;
Radix::Any { radix, min_len }
})
}
with either use std::convert::TryFrom;
, or edition = "2021"
in Cargo.toml
.
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.
Ah yes, we can indeed use u32::count_ones
and u32::leading_zeros
now (they were added in 1.32, seven months after I wrote fpe 0.1
for Sapling). I also bumped MSRV to 1.56 for this upcoming release, so we can use edition = "2021"
as well. I'll make both of these changes in a separate PR (as it's unrelated to the changes in this one).
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.
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.
ACK, no changes from the last time I reviewed this.
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.
utACK with suggestions (I believe the unresolved ones are now just in comments).
Co-authored-by: Daira Hopwood <[email protected]>
criterion 0.4 now has an MSRV of 1.59 due to its dependencies, and pprof has an MSRV of 1.64 due to its dependencies. This is a follow-on to 0c53a91.
No description provided.