Skip to content

std: optimise IO error formatting - #161945

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
joboet:format_error
Aug 29, 2026
Merged

std: optimise IO error formatting#161945
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
joboet:format_error

Conversation

@joboet

@joboet joboet commented Aug 28, 2026

Copy link
Copy Markdown
Member

The current OS error formatting logic goes through a bit of trouble (the format! macro, temporary allocations and unnecessary copying) to create a String for Formatter::write_str. It's more efficient and arguably simpler to have the formatting logic write into the Formatter directly instead.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 28, 2026
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from ChrisDenton, JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

@hanna-kruppe

Copy link
Copy Markdown
Contributor

It's not obvious to me that this is meaningfully more efficient on the most important targets, nor that formatting performance matters, but:

  1. I didn't see anything that gives me reason to suspect something will get slower.
  2. Avoiding (all or some) temporary allocations is certainly neat.
  3. I agree it's conceptually more appropriate to write this as formatting code rather than string-producing code.

r? me @bors r+ rollup=iffy (lots of tier 2-3 targets touched, may want more try runs for those not tested in PR CI)

Let's also see if perf has anything to say about this on Linux: @bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d20d512 has been approved by hanna-kruppe

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 28, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 28, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
std: optimise IO error formatting
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: fb25bc1 (fb25bc125ff5e59181244e62cf702d54534fb687)
Base parent: 17fd5b8 (17fd5b8a37b6667b6cc137f3cc35f09759768a3b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (fb25bc1): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 1

Max RSS (memory usage)

Results (primary 6.6%, secondary 1.6%)

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

mean range count
Regressions ❌
(primary)
6.6% [6.6%, 6.6%] 1
Regressions ❌
(secondary)
6.5% [6.5%, 6.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) 6.6% [6.6%, 6.6%] 1

Cycles

This perf run didn't have relevant results for this metric.

Binary size

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

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 4
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 4

Bootstrap: 474.378s -> 479.281s (1.03%)
Artifact size: 402.85 MiB -> 402.92 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 28, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #160170 (Refactored docs for `std::fs::set_permissions_nofollow` + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag)
 - #161945 (std: optimise IO error formatting)
 - #160594 (attach global target features to module-level assembly)
 - #161577 (implement [u8]::split_ascii_whitespace)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161897 (Reject contract attributes without arguments)
 - #161909 (Report the configured Polonius default in -Z help)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #161945 (std: optimise IO error formatting)
 - #160594 (attach global target features to module-level assembly)
 - #161577 (implement [u8]::split_ascii_whitespace)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161897 (Reject contract attributes without arguments)
 - #161909 (Report the configured Polonius default in -Z help)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit d20d512 with merge db9e342...

Workflow: https://github.com/rust-lang/rust/actions/runs/33226819888

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 29, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
@Zalathar

Copy link
Copy Markdown
Member

@bors yield (to enclosing rollup)

@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #161955.

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
Rollup of 17 pull requests

Successful merges:

 - #161945 (std: optimise IO error formatting)
 - #160594 (attach global target features to module-level assembly)
 - #161577 (implement [u8]::split_ascii_whitespace)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161897 (Reject contract attributes without arguments)
 - #161909 (Report the configured Polonius default in -Z help)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
 - #161924 (Windows: document that `normalize_lexically` converts `/` to `\`)
 - #161927 (Change `rustc_middle/src/hooks/mod.rs` to `hooks.rs`)
@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit d20d512 with merge 7891f5c...

Workflow: https://github.com/rust-lang/rust/actions/runs/33230199594

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
@Zalathar

Copy link
Copy Markdown
Member

@bors yield (rollup again)

@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #161955.

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
Rollup of 17 pull requests

Successful merges:

 - #161945 (std: optimise IO error formatting)
 - #160594 (attach global target features to module-level assembly)
 - #161577 (implement [u8]::split_ascii_whitespace)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161897 (Reject contract attributes without arguments)
 - #161909 (Report the configured Polonius default in -Z help)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
 - #161924 (Windows: document that `normalize_lexically` converts `/` to `\`)
 - #161927 (Change `rustc_middle/src/hooks/mod.rs` to `hooks.rs`)
@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit d20d512 with merge ab5a24f...

Workflow: https://github.com/rust-lang/rust/actions/runs/33235152627

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
@jhpratt

jhpratt commented Aug 29, 2026

Copy link
Copy Markdown
Member

yielding to rollup

@bors yield

@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #161959.

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
Rollup of 17 pull requests

Successful merges:

 - #161945 (std: optimise IO error formatting)
 - #160594 (attach global target features to module-level assembly)
 - #161577 (implement [u8]::split_ascii_whitespace)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161888 (compiler: Allow safestack to be togglable via #[sanitize(safestack = "...")])
 - #161897 (Reject contract attributes without arguments)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
 - #161924 (Windows: document that `normalize_lexically` converts `/` to `\`)
 - #161927 (Change `rustc_middle/src/hooks/mod.rs` to `hooks.rs`)
@rust-bors
rust-bors Bot merged commit af94503 into rust-lang:main Aug 29, 2026
14 of 15 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 29, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
Rollup merge of #161945 - joboet:format_error, r=hanna-kruppe

std: optimise IO error formatting

The current OS error formatting logic goes through a bit of trouble (the `format!` macro, temporary allocations and unnecessary copying) to create a `String` for `Formatter::write_str`. It's more efficient and arguably simpler to have the formatting logic write into the `Formatter` directly instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants