Skip to content

Conversation

@m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Nov 5, 2025

Part of #99012

Continuation of #137294

This is an experimental new implementation of fmt::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, this fmt::Arguments can store a &'static str without any indirection or additional storage. This means that simple cases like print_fmt(format_args!("hello")) are now just as efficient for the caller as print_str("hello"), as shown by this example:

code:

fn main() {
    println!("Hello, world!");
}

before:

main:
 sub     rsp, 56
 lea     rax, [rip + .Lanon_hello_world]
 mov     qword ptr [rsp + 8], rax
 mov     qword ptr [rsp + 16], 1
 mov     qword ptr [rsp + 24], 8
 xorps   xmm0, xmm0
 movups  xmmword ptr [rsp + 32], xmm0
 lea     rdi, [rsp + 8]
 call    qword ptr [rip + std::io::stdio::_print]
 add     rsp, 56
 ret

after:

main:
 lea     rsi, [rip + .Lanon_hello_world]
 mov     edi, 29
 jmp     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

@m-ou-se m-ou-se self-assigned this Nov 5, 2025
@m-ou-se m-ou-se added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-fmt Area: `core::fmt` labels Nov 5, 2025
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 5, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 5, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2025
@rust-log-analyzer

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Nov 5, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 5, 2025

☀️ 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.

mean range count
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.

mean range count
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.

mean range count
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.

mean range count
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%)

@rustbot rustbot added the perf-regression Performance regression. label Nov 6, 2025
@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3b95bd4): 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.

mean range count
Regressions ❌
(primary)
1.7% [0.1%, 22.0%] 120
Regressions ❌
(secondary)
0.9% [0.1%, 11.2%] 49
Improvements ✅
(primary)
-0.7% [-3.6%, -0.1%] 45
Improvements ✅
(secondary)
-2.0% [-36.4%, -0.0%] 62
All ❌✅ (primary) 1.1% [-3.6%, 22.0%] 165

Max RSS (memory usage)

Results (primary 2.2%, secondary 1.7%)

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

mean range count
Regressions ❌
(primary)
2.9% [1.1%, 7.5%] 20
Regressions ❌
(secondary)
2.7% [1.3%, 5.9%] 11
Improvements ✅
(primary)
-2.0% [-2.9%, -1.0%] 3
Improvements ✅
(secondary)
-3.6% [-3.7%, -3.6%] 2
All ❌✅ (primary) 2.2% [-2.9%, 7.5%] 23

Cycles

Results (primary 5.5%, secondary -2.8%)

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

mean range count
Regressions ❌
(primary)
5.9% [1.6%, 14.2%] 28
Regressions ❌
(secondary)
4.4% [1.8%, 9.8%] 13
Improvements ✅
(primary)
-4.5% [-4.5%, -4.5%] 1
Improvements ✅
(secondary)
-10.0% [-38.0%, -1.8%] 13
All ❌✅ (primary) 5.5% [-4.5%, 14.2%] 29

Binary size

Results (primary 0.5%, secondary -0.2%)

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

mean range count
Regressions ❌
(primary)
1.4% [0.0%, 5.3%] 71
Regressions ❌
(secondary)
2.9% [0.0%, 10.6%] 30
Improvements ✅
(primary)
-0.6% [-2.1%, -0.0%] 51
Improvements ✅
(secondary)
-1.2% [-11.3%, -0.0%] 101
All ❌✅ (primary) 0.5% [-2.1%, 5.3%] 122

Bootstrap: 474.482s -> 474.113s (-0.08%)
Artifact size: 390.74 MiB -> 388.33 MiB (-0.62%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 6, 2025

I have no clue what to do with these numbers. Ideas and suggestions very welcome.

@rust-log-analyzer

This comment has been minimized.

@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 6, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 6, 2025
Experiment: New fmt::Arguments implementation
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2025
@rust-bors
Copy link

rust-bors bot commented Nov 6, 2025

☀️ Try build successful (CI)
Build commit: fbb43aa (fbb43aa2e4f4bc9f6b7d8185976b444e49bbef87, parent: c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fbb43aa): 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.

mean range count
Regressions ❌
(primary)
1.7% [0.1%, 21.1%] 104
Regressions ❌
(secondary)
0.7% [0.0%, 5.5%] 43
Improvements ✅
(primary)
-0.6% [-3.6%, -0.1%] 49
Improvements ✅
(secondary)
-2.0% [-37.0%, -0.1%] 62
All ❌✅ (primary) 1.0% [-3.6%, 21.1%] 153

Max RSS (memory usage)

Results (primary 1.0%, secondary -0.7%)

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

mean range count
Regressions ❌
(primary)
2.2% [0.9%, 4.2%] 16
Regressions ❌
(secondary)
2.5% [1.2%, 3.4%] 5
Improvements ✅
(primary)
-2.9% [-4.2%, -1.9%] 5
Improvements ✅
(secondary)
-3.0% [-4.9%, -1.7%] 7
All ❌✅ (primary) 1.0% [-4.2%, 4.2%] 21

Cycles

Results (primary 5.3%, secondary -4.9%)

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

mean range count
Regressions ❌
(primary)
6.0% [2.0%, 13.0%] 11
Regressions ❌
(secondary)
3.9% [2.1%, 7.9%] 6
Improvements ✅
(primary)
-1.7% [-1.7%, -1.7%] 1
Improvements ✅
(secondary)
-8.4% [-38.7%, -1.4%] 15
All ❌✅ (primary) 5.3% [-1.7%, 13.0%] 12

Binary size

Results (primary 0.5%, secondary -0.3%)

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

mean range count
Regressions ❌
(primary)
1.4% [0.0%, 5.3%] 72
Regressions ❌
(secondary)
2.9% [0.0%, 10.0%] 29
Improvements ✅
(primary)
-0.6% [-2.2%, -0.0%] 60
Improvements ✅
(secondary)
-1.2% [-11.3%, -0.0%] 103
All ❌✅ (primary) 0.5% [-2.2%, 5.3%] 132

Bootstrap: 475.185s -> 473.728s (-0.31%)
Artifact size: 390.81 MiB -> 388.34 MiB (-0.63%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 7, 2025

Seems like a lot of time is spent in live_symbols_and_ignored_derived_traits.

generate_crate_metadata also went up somewhat significantly, together with size:crate_metadata going up a lot in many cases. 🤔

@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 10, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 10, 2025
Experiment: New fmt::Arguments implementation
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 10, 2025
@rust-bors
Copy link

rust-bors bot commented Nov 10, 2025

☀️ Try build successful (CI)
Build commit: 2f456ca (2f456ca5a02a06d0f2256251c601b1811cc47ac3, parent: 00426d642ad6a8c6192bf517702a68b0a8001547)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2f456ca): 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.

mean range count
Regressions ❌
(primary)
1.7% [0.1%, 21.2%] 107
Regressions ❌
(secondary)
0.7% [0.0%, 5.7%] 46
Improvements ✅
(primary)
-0.7% [-3.5%, -0.1%] 46
Improvements ✅
(secondary)
-1.9% [-36.7%, -0.1%] 63
All ❌✅ (primary) 1.0% [-3.5%, 21.2%] 153

Max RSS (memory usage)

Results (primary 0.9%, secondary 0.5%)

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

mean range count
Regressions ❌
(primary)
2.3% [1.2%, 4.0%] 18
Regressions ❌
(secondary)
4.2% [1.1%, 6.9%] 13
Improvements ✅
(primary)
-2.3% [-3.7%, -0.6%] 8
Improvements ✅
(secondary)
-3.3% [-6.0%, -2.0%] 13
All ❌✅ (primary) 0.9% [-3.7%, 4.0%] 26

Cycles

Results (primary 6.3%, secondary -3.7%)

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

mean range count
Regressions ❌
(primary)
6.3% [3.3%, 13.7%] 9
Regressions ❌
(secondary)
4.8% [1.6%, 9.8%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-11.3% [-38.2%, -2.0%] 10
All ❌✅ (primary) 6.3% [3.3%, 13.7%] 9

Binary size

Results (primary 0.5%, secondary -0.3%)

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

mean range count
Regressions ❌
(primary)
1.4% [0.0%, 5.3%] 72
Regressions ❌
(secondary)
2.9% [0.0%, 10.0%] 29
Improvements ✅
(primary)
-0.6% [-2.2%, -0.0%] 61
Improvements ✅
(secondary)
-1.2% [-11.3%, -0.0%] 104
All ❌✅ (primary) 0.5% [-2.2%, 5.3%] 133

Bootstrap: 476.293s -> 472.782s (-0.74%)
Artifact size: 391.34 MiB -> 388.55 MiB (-0.71%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 10, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 11, 2025

Closing this in favor of #148789, which has much better results 🎉

@m-ou-se m-ou-se closed this Nov 11, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-fmt Area: `core::fmt` perf-regression Performance regression. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants