-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Experiment: fmt::Arguments as closure #101568
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit cad2895eacd510f7b6474a85f7ff4d777fcb7368 with merge b1b62d59ec191dbd9702e1435014673d12e3d3df... |
562b8c7
to
05fefb7
Compare
This comment has been minimized.
This comment has been minimized.
At the risk of microoptimization: might it be worth recognizing the extremely common case of a single-character |
I'm incredibly excited about this, and in particular I'm excited for being able to give the optimizer more optimization opportunities. |
@joshtriplett |
This comment was marked as resolved.
This comment was marked as resolved.
With efficient lookup through a hash map.
80563fc
to
31f4114
Compare
This comment has been minimized.
This comment has been minimized.
2951fbd
to
70b63e7
Compare
This comment has been minimized.
This comment has been minimized.
The number of line drawing characters depends on the number of digits in the allocation number. This removes the characters to avoid spurious failures.
70b63e7
to
e45a26c
Compare
Okay let's try a perf run.. I'm not expecting great results, because this just tests rustc itself. The approach in this PR results in a closure per format_args!(), meaning more codegen and more work for the optimizer. We'll need separate benchmarking for runtime performance. The try build will also allow folks to easily test out this implementation using rustup-toolchain-install-master. @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit e45a26c with merge 4edeac5d8399ad2a61ee852f523d95f5be83429a... |
☀️ Try build successful - checks-actions |
Queued 4edeac5d8399ad2a61ee852f523d95f5be83429a with parent c97922d, future comparison URL. |
Finished benchmarking commit (4edeac5d8399ad2a61ee852f523d95f5be83429a): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never 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.
Footnotes |
Yup, that's exactly as expected. ^^ The There might be ways to improve the compiler performance, but for now I'm not going to address this. The purpose of this experimental PR for now is to see what the effect of such an approach can be on runtime performance and binary size. Only if we conclude this might be the best approach for runtime performance and binary size, is it worth looking into compiler performance. |
Interestingly, some of the |
Closing this as it was an experiment. |
l |
This is part of #99012
This implements the "closure idea" for fmt::Arguments.
For now it uses a simple
enum { Fn(&'a dyn Fn), StaticStr(&'static str) }
to handle the static str case foras_str()
. A slightly more optimized version could reduce the size offmt::Arguments
to two pointers with some tricks.Includes #100996 and #101569
With this,
println!("Hello, {0} {0:x} {0:#x}!", 100)
expands to: