-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Optimize Symbol::integer
by utilizing in-place formatting
#122102
Conversation
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Optimize `Symbol::integer` by utilizing in-place formatting This PR optimize `Symbol::integer` by utilizing `itoa` in-place formatting instead of going through a dynamically allocated `String` and the format machinery. <details> For some context: I was profiling `rustc --check-cfg` with callgrind and due to the way we currently setup all the targets and we end-up calling `Symbol::integer` multiple times for all the targets. Using `itoa` reduced the number of instructions. </details>
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (379d309): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 644.65s -> 646.027s (0.21%) |
@@ -2325,13 +2325,15 @@ pub mod sym { | |||
/// | |||
/// The first few non-negative integers each have a static symbol and therefore | |||
/// are fast. | |||
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol { | |||
pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol { | |||
if let Result::Ok(idx) = n.try_into() { |
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.
Unrelated to the PR, but why does this use Result::Ok
instead of just Ok
? D:
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.
No idea. The original commit even had Option::Some
😅.
Perf shows no distinguishable improvement, but it never hurts to remove useless work. |
@bors r= |
I need to type more slowly. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9d272a1): comparison URL. Overall result: ❌✅ regressions and improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 650.646s -> 649.534s (-0.17%) |
This PR optimize
Symbol::integer
by utilizingitoa
in-place formatting instead of going through a dynamically allocatedString
and the format machinery.For some context: I was profiling
rustc --check-cfg
with callgrind and due to the way we currently setup all the targets and we end-up callingSymbol::integer
multiple times for all the targets. Usingitoa
reduced the number of instructions.