-
Notifications
You must be signed in to change notification settings - Fork 14k
New format_args!() and fmt::Arguments implementation #148789
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
base: main
Are you sure you want to change the base?
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Experiment: New fmt::Arguments implementation (another one)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (6e6ba94): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -1.5%, secondary -0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.5%, secondary -4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.7%, secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 476.631s -> 471.922s (-0.99%) |
|
Ooh that's pretty good :D |
|
Pretty much everything looks like a great improvement. Not only number of instructions executed, but also memory usage and binary size. 🎉 Only two significant negative results: 1. "image-0.25.6 opt incr-patched:println" with almost +6% instructions:u.Looking at the detailed results, it looks like that's all LLVM. Probably because llvm got more optimization opportunities. That's not necessarily a bad thing. 2. The
|
9f41692 to
349d2b5
Compare
349d2b5 to
5b58c66
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Experiment: New fmt::Arguments implementation (another one)
|
☔ The latest upstream changes (presumably #148851) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Heads up that you might also need to do |
dc7f0eb to
5512e36
Compare
We don't need it anymore.
5512e36 to
9b48431
Compare
|
There are probably tons of micro optimizations left we can do; lots of ways in which we can tweak the exact encoding that makes it faster to execute. But this PR as it is seems good enough and a clear improvement, so I'd like to get this merged first and then do smaller tweaks in later PRs that we can then individually benchmark. |
|
The If I move the |
|
So, summary: This improves rustc performance (0-1%, peaks up to 40%), improves rustc memory usage (1-2%, even 3-4% for Hello World and Ripgrep), improves binary size (~1%, close to 2% for both Hello World and Cargo), and improves runtime performance (0-2%, up to 30% in extreme cases). The few losses can be attributed to llvm getting more optimization opportunities (e.g. the image-0.25.6 test) and an an unrealistic benchmark. |

Part of #99012
This is a new implementation of
fmt::Arguments. In this implementation,fmt::Argumentsis only two pointers in size. (Instead of six, before.) This makes it the same size as a&strand makes it fit in a register pair.This
fmt::Argumentscan store a&'static strwithout any indirection or additional storage. This means that simple cases likeprint_fmt(format_args!("hello"))are now just as efficient for the caller asprint_str("hello"), as shown by this example:(
panic!("Hello, world!");shows a similar change.)This implementation stores all static information as just a single (byte) string, without any indirection:
This saves a ton of pointers and simplifies the expansion significantly, but does mean that individual pieces (e.g.
"Hello, "and"!\n") cannot be reused. (Those pieces are often smaller than a pointer to them, though, in which case reusing them is useless.)The details of the new representation are documented in library/core/src/fmt/mod.rs.