Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Experiment: New fmt::Arguments implementation#148529

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
m-ou-se wants to merge9 commits intorust-lang:master
base:master
Choose a base branch
Loading
fromm-ou-se:new-fmt-args

Conversation

@m-ou-se
Copy link
Member

@m-ou-sem-ou-se commentedNov 5, 2025
edited
Loading

Part of#99012

Continuation of#137294

This is an experimental new implementation offmt::Arguments. In this implementation,fmt::Arguments is only two pointers in size. (Instead of six, currently.) This makes it the same size as a&str and makes it fit in a register pair.

Additionally, thisfmt::Arguments can 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:

code:

fnmain(){println!("Hello, world!");}

before:

main:subrsp,56learax,[rip+ .Lanon_hello_world]mov     qword ptr[rsp+8],raxmov     qword ptr[rsp+16],1mov     qword ptr[rsp+24],8xorpsxmm0,xmm0movups  xmmword ptr[rsp+32],xmm0leardi,[rsp+8]call    qword ptr[rip+std::io::stdio::_print]addrsp,56ret

after:

main:learsi,[rip+ .Lanon_hello_world]movedi,29jmp     qword ptr[rip+std::io::stdio::_print]

Similarly,panic!("Hello, world!"); shows the same change.

To do:

  • Performance testing
  • Figure out why things are slower to compile
  • Fix compilation performance
  • Documentation / comments

Kobzol, yotamofek, and smmalis37 reacted with rocket emojitheemathas and smmalis37 reacted with eyes emoji
@m-ou-sem-ou-se self-assigned thisNov 5, 2025
@m-ou-sem-ou-se added T-compilerRelevant to the compiler team, which will review and decide on the PR/issue. T-libsRelevant to the library team, which will review and decide on the PR/issue. A-fmtArea: `core::fmt` labelsNov 5, 2025
@rustbotrustbot added the S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author. labelNov 5, 2025
@m-ou-se
Copy link
MemberAuthor

@bors try@rust-timer queue

@rust-timer

This comment has been minimized.

rust-borsbot added a commit that referenced this pull requestNov 5, 2025
Experiment: New fmt::Arguments implementation
@rust-bors

This comment has been minimized.

@rustbotrustbot added the S-waiting-on-perfStatus: Waiting on a perf run to be completed. labelNov 5, 2025
@rust-log-analyzer

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rustbotrustbot added the T-clippyRelevant to the Clippy team. labelNov 5, 2025
@rust-log-analyzer
Copy link
Collaborator

The jobaarch64-gnu-llvm-20-1 failed! Check out the build log:(web)(plain enhanced)(plain)

Click to see the possible cause of the failure (guessed by this bot)
test [mir-opt] tests/mir-opt/unusual_item_types.rs ... okfailures:---- [mir-opt] tests/mir-opt/sroa/lifetimes.rs stdout ----18       let mut _18: core::fmt::rt::Argument<'_>;19       let mut _19: &u32;20       let mut _20: core::fmt::rt::Template<'_>;-       let mut _21: &[core::fmt::rt::Piece; 7];-       let _22: &[core::fmt::rt::Piece; 7];-       let _23: [core::fmt::rt::Piece; 7];+       let mut _21: &[core::fmt::rt::Piece; 6];+       let _22: &[core::fmt::rt::Piece; 6];+       let _23: [core::fmt::rt::Piece; 6];24       let mut _24: core::fmt::rt::Piece;25       let mut _25: core::fmt::rt::Piece;26       let mut _26: core::fmt::rt::Piece;27       let mut _27: core::fmt::rt::Piece;28       let mut _28: core::fmt::rt::Piece;29       let mut _29: core::fmt::rt::Piece;-       let mut _30: core::fmt::rt::Piece;-       let mut _31: &[core::fmt::rt::Argument<'_>; 2];-       let _32: &[core::fmt::rt::Argument<'_>; 2];-       let mut _34: &std::boxed::Box<dyn std::fmt::Display>;-       let mut _35: &u32;-       let mut _36: bool;+       let mut _30: &[core::fmt::rt::Argument<'_>; 2];+       let _31: &[core::fmt::rt::Argument<'_>; 2];+       let mut _33: &std::boxed::Box<dyn std::fmt::Display>;+       let mut _34: &u32;+       let mut _35: bool;+       let mut _36: isize;36       let mut _37: isize;37       let mut _38: isize;-       let mut _39: isize;- +     let _40: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>;- +     let _41: u32;+ +     let _39: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>;+ +     let _40: u32;41       scope 1 {42 -         debug foo => _1;- +         debug ((foo: Foo<T>).0: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>) => _40;- +         debug ((foo: Foo<T>).1: u32) => _41;+ +         debug ((foo: Foo<T>).0: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>) => _39;+ +         debug ((foo: Foo<T>).1: u32) => _40;45           let _5: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>;46           scope 2 {47               debug x => _5;52                       debug x => _8;53                       let _8: std::boxed::Box<dyn std::fmt::Display>;54                       let _12: (&std::boxed::Box<dyn std::fmt::Display>, &u32);- +                     let _42: &std::boxed::Box<dyn std::fmt::Display>;- +                     let _43: &u32;+ +                     let _41: &std::boxed::Box<dyn std::fmt::Display>;+ +                     let _42: &u32;57                       scope 5 {58 -                         debug args => _12;- +                         debug ((args: (&Box<dyn std::fmt::Display>, &u32)).0: &std::boxed::Box<dyn std::fmt::Display>) => _42;- +                         debug ((args: (&Box<dyn std::fmt::Display>, &u32)).1: &u32) => _43;+ +                         debug ((args: (&Box<dyn std::fmt::Display>, &u32)).0: &std::boxed::Box<dyn std::fmt::Display>) => _41;+ +                         debug ((args: (&Box<dyn std::fmt::Display>, &u32)).1: &u32) => _42;61                           let _15: [core::fmt::rt::Argument<'_>; 2];62                           scope 6 {63                               debug args => _15;-                               let mut _33: &[core::fmt::rt::Piece; 7];+                               let mut _32: &[core::fmt::rt::Piece; 6];65                           }66                       }67                   }70       }---77 +         nop;78           StorageLive(_2);79           StorageLive(_3);87           _2 = Result::<Box<dyn std::fmt::Display>, <T as Err>::Err>::Ok(move _3);88           StorageDead(_3);89 -         _1 = Foo::<T> { x: move _2, y: const 7_u32 };- +         _40 = move _2;- +         _41 = const 7_u32;+ +         _39 = move _2;+ +         _40 = const 7_u32;92 +         nop;93           StorageDead(_2);94           StorageLive(_5);-           _36 = const true;+           _35 = const true;96 -         _5 = move (_1.0: std::result::Result<std::boxed::Box<dyn std::fmt::Display>, <T as Err>::Err>);- +         _5 = move _40;+ +         _5 = move _39;98           StorageLive(_6);99 -         _6 = copy (_1.1: u32);- +         _6 = copy _41;+ +         _6 = copy _40;101           _7 = discriminant(_5);102           switchInt(move _7) -> [0: bb2, otherwise: bb8];103       }109           StorageLive(_10);110           StorageLive(_11);111 -         StorageLive(_12);---115           StorageLive(_13);116           _13 = &_8;117           StorageLive(_14);118           _14 = &_6;119 -         _12 = (move _13, move _14);- +         _42 = move _13;- +         _43 = move _14;+ +         _41 = move _13;+ +         _42 = move _14;122 +         nop;123           StorageDead(_14);124           StorageDead(_13);125           StorageLive(_15);126           StorageLive(_16);127           StorageLive(_17);- -         _34 = copy (_12.0: &std::boxed::Box<dyn std::fmt::Display>);- +         _34 = copy _42;-           _17 = &(*_34);+ -         _33 = copy (_12.0: &std::boxed::Box<dyn std::fmt::Display>);+ +         _33 = copy _41;+           _17 = &(*_33);131           _16 = core::fmt::rt::Argument::<'_>::new_display::<Box<dyn std::fmt::Display>>(move _17) -> [return: bb3, unwind unreachable];132       }133   135           StorageDead(_17);136           StorageLive(_18);137           StorageLive(_19);- -         _35 = copy (_12.1: &u32);- +         _35 = copy _43;-           _19 = &(*_35);+ -         _34 = copy (_12.1: &u32);+ +         _34 = copy _42;+           _19 = &(*_34);141           _18 = core::fmt::rt::Argument::<'_>::new_display::<u32>(move _19) -> [return: bb4, unwind unreachable];142       }143   149           StorageLive(_20);150           StorageLive(_21);151           StorageLive(_22);-           _33 = const foo::<T>::promoted[0];-           _22 = &(*_33);+           _32 = const foo::<T>::promoted[0];+           _22 = &(*_32);154           _21 = &(*_22);-           _20 = core::fmt::rt::Template::<'_>::new::<7>(move _21) -> [return: bb5, unwind unreachable];+           _20 = core::fmt::rt::Template::<'_>::new::<6>(move _21) -> [return: bb5, unwind unreachable];156       }157   158       bb5: {159           StorageDead(_22);160           StorageDead(_21);+           StorageLive(_30);161           StorageLive(_31);-           StorageLive(_32);-           _32 = &_15;-           _31 = &(*_32);-           _11 = core::fmt::rt::<impl Arguments<'_>>::new::<2>(move _20, move _31) -> [return: bb6, unwind unreachable];+           _31 = &_15;+           _30 = &(*_31);+           _11 = core::fmt::rt::<impl Arguments<'_>>::new::<2>(move _20, move _30) -> [return: bb6, unwind unreachable];166       }167   168       bb6: {-           StorageDead(_32);170           StorageDead(_31);+           StorageDead(_30);171           StorageDead(_20);172           _10 = _eprint(move _11) -> [return: bb7, unwind unreachable];173       }176           StorageDead(_11);177           StorageDead(_15);178 -         StorageDead(_12);---198   199       bb10: {200           StorageDead(_6);-           _37 = discriminant(_5);-           switchInt(move _37) -> [0: bb11, otherwise: bb12];+           _36 = discriminant(_5);+           switchInt(move _36) -> [0: bb11, otherwise: bb12];203       }204   205       bb11: {-           _36 = const false;---212           return;213       }thread '[mir-opt] tests/mir-opt/sroa/lifetimes.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:84:21:Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/sroa/lifetimes.foo.ScalarReplacementOfAggregates.diffstack backtrace:   5: __rustc::rust_begin_unwind             at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/panicking.rs:698:5   6: core::panicking::panic_fmt             at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/core/src/panicking.rs:80:14

@rust-bors
Copy link

☀️ Try build successful (CI)
Build commit:89ea077 (89ea077499c3fe06868ef1d91f2c47c8af941dce, parent:53efb3d4f3b67d189a0c72eb475a52017d79d609)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (89ea077):comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking 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@rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

meanrangecount
Regressions ❌
(primary)
0.9%[0.1%, 8.4%]95
Regressions ❌
(secondary)
1.1%[0.0%, 12.0%]37
Improvements ✅
(primary)
-0.6%[-2.2%, -0.1%]39
Improvements ✅
(secondary)
-2.1%[-35.3%, -0.0%]55
All ❌✅ (primary)0.5%[-2.2%, 8.4%]134

Max RSS (memory usage)

Results (primary 1.6%, secondary -0.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
2.7%[1.0%, 5.5%]22
Regressions ❌
(secondary)
4.3%[2.2%, 8.9%]7
Improvements ✅
(primary)
-2.6%[-6.5%, -0.6%]6
Improvements ✅
(secondary)
-3.6%[-5.6%, -1.5%]12
All ❌✅ (primary)1.6%[-6.5%, 5.5%]28

Cycles

Results (primary 4.5%, secondary -4.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
6.8%[1.7%, 11.0%]13
Regressions ❌
(secondary)
5.8%[2.2%, 11.1%]7
Improvements ✅
(primary)
-3.1%[-5.8%, -2.1%]4
Improvements ✅
(secondary)
-8.8%[-36.8%, -2.4%]16
All ❌✅ (primary)4.5%[-5.8%, 11.0%]17

Binary size

Results (primary -0.2%, secondary -0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
0.4%[0.0%, 2.2%]24
Regressions ❌
(secondary)
3.7%[0.1%, 19.5%]26
Improvements ✅
(primary)
-0.4%[-2.2%, -0.0%]100
Improvements ✅
(secondary)
-1.2%[-11.2%, -0.0%]105
All ❌✅ (primary)-0.2%[-2.2%, 2.2%]124

Bootstrap: 473.384s -> 471.178s (-0.47%)
Artifact size: 390.72 MiB -> 387.77 MiB (-0.75%)

@rustbotrustbot added the perf-regressionPerformance regression. labelNov 6, 2025
@rustbotrustbot removed the S-waiting-on-perfStatus: Waiting on a perf run to be completed. labelNov 6, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

@m-ou-sem-ou-se

Labels

A-fmtArea: `core::fmt`perf-regressionPerformance regression.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-clippyRelevant to the Clippy team.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@m-ou-se@rust-timer@rust-log-analyzer@rustbot

[8]ページ先頭

©2009-2025 Movatter.jp