-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Faster parsing for lower numbers for radix up to 16 #83371
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@gilescope Ping from triage! CI is still red here. Mind fixing that? |
I believe the other pull request superseeds this pull request. Which @gilescope is still experimenting with. |
@pickfire while I'd like to find a way to improve base10 parsing specifically, this is a simple speedup for all radix with little down side. It focuses on small numbers which are in general more common so it's likely to kick in most of the time. I think given the simplicity we should move forward with this PR. |
You may also want to write down how small there. |
This comment has been minimized.
This comment has been minimized.
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.
Two more nits and you might want to squash down your commits a bit but otherwise LGTM.
Co-authored-by: LingMan <[email protected]>
Hmm, redoing the perf testing pulling out |
@gilescope Ping from triage, what's next steps here? |
@gilescope Ping from triage, any updates here? |
@gilescope Ping from triage. Can you please post the status of this MR? |
@gilescope Does replacing the contents of the macro_rules! run_loop {
($unchecked_additive_op:ident) => {
for &c in digits {
result = result.unchecked_mul(radix);
let x = (c as char).to_digit(radix).ok_or(PIE { kind: InvalidDigit })?;
result = T::$unchecked_additive_op(&result, x);
}
}
}
if is_positive { run_loop!(unchecked_add) } else { run_loop!(unchecked_sub) }; |
@gilescope @rustbot label: +S-inactive |
@JohnCSimon can we reopen this PR. I didn't see LingMan's comment. I think this is good now with LingMan's change. Is it possible to kick off a perf run? (I've rebased to bring this up to date with master) |
(Sorry I've been away a long time.) |
the branch was force-pushed or recreated so the PR can't be re-opened. you could submit a new PR. |
Faster parsing for lower numbers for radix up to 16 (cont.) ( Continuation of rust-lang#83371 ) With LingMan's change I think this is potentially ready.
Faster parsing for lower numbers for radix up to 16 (cont.) ( Continuation of rust-lang/rust#83371 ) With LingMan's change I think this is potentially ready.
While musing on #83088 I noticed that we could use str len to establish if the input was guarenteed not to overflow the containing type.
From what I can see this is conservative enough (i64 having the least wiggle room) that we can safely skip the overflow checks because we have ruled out overflow and that seems to improve performance by 1/4 to 1/3 for numbers in the range. Given that most numbers are statistically on the small side rather than near the type limits, I'm tempted by this. As it stands it doesn't really help i8 much as it's so small a range of numbers, but it does work well with u8 (
FF
) which is far more common.I don't like adding unsafety, but this might be worth it.