Skip to content

perf: mark error handling functions as cold and non-inlineable - #14801

Merged
sylvestre merged 2 commits into
uutils:mainfrom
xtqqczze:cold-error-size
Oct 6, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
xtqqczze:cold-error-size

Conversation

@xtqqczze

@xtqqczze xtqqczze commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Error construction is infrequently executed compared with the normal success paths. Mark these functions with #[cold] so the compiler can treat them as unlikely code paths and keep cold code separate from hot code.

Use #[inline(never)] to prevent error-handling code from being inlined into their callers, avoiding unnecessary code-size growth and keeping the normal execution paths smaller.

We get a nice size reduction for release profile (33.7 KiB):

git checkout --quiet b198c70a2e8d2824605caf7a040d852debe1d566
cargo build --quiet --profile=release --target aarch64-apple-darwin && wc -c < target/aarch64-apple-darwin/release/coreutils
git checkout --quiet cold-error-size
cargo build --quiet --profile=release --target aarch64-apple-darwin && wc -c < target/aarch64-apple-darwin/release/coreutils
 9938064
 9903520

But but not for release-small:

git checkout --quiet b198c70a2e8d2824605caf7a040d852debe1d566
cargo build --quiet --profile=release-small --target aarch64-apple-darwin && wc -c < target/aarch64-apple-darwin/release-small/coreutils
git checkout --quiet cold-error-size
cargo build --quiet --profile=release-small --target aarch64-apple-darwin && wc -c < target/aarch64-apple-darwin/release-small/coreutils
 6057056
 6057088

Measurements taken from 3b62942 (head) vs b198c70 (base).

@codspeed

codspeed Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.03%

⚡ 5 improved benchmarks
❌ 2 regressed benchmarks
✅ 390 untouched benchmarks
🆕 2 new benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation three_39_bit_primes 228.6 ms 583.9 ms -60.85%
❌ Simulation five_38_bit_primes 1.8 s 1.8 s -3.98%
⚡ Simulation thirteen_39_bit_primes 9.2 s 8.6 s +7.02%
⚡ Simulation du_wide_tree[(5000, 500)] 15.9 ms 15.2 ms +4.85%
⚡ Simulation tr_single_char_replace 14.5 ms 13.9 ms +4.26%
⚡ Simulation unexpand_large_file[10] 286.2 ms 274.8 ms +4.18%
⚡ Simulation unexpand_many_lines[100000] 136.9 ms 131.4 ms +4.17%
🆕 Memory tr_delete_single_char N/A 35.4 KB N/A
🆕 Simulation tr_delete_single_char N/A 103.9 ms N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing xtqqczze:cold-error-size (1d5c49a) with main (968853a)2

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (f29e308) during the generation of this report, so 968853a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)

@xtqqczze
xtqqczze marked this pull request as ready for review September 22, 2026 15:05
Comment thread src/uucore/src/lib/mods/error.rs
Comment thread src/uu/cp/locales/en-US.ftl Outdated
cp-error-same-file = { $source } and { $dest } are the same file
cp-error-backing-up-destroy-source = backing up { $dest } might destroy source; { $source } not copied
cp-error-cannot-open-for-reading = cannot open { $source } for reading
cp-error-cannot-open-for-reading = cannot open { $source } for reading: permission denied

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gnu prints "Permission denied" with a capital P here. could you please keep the message and the io error separate?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this would be fixing a regression from #5004.

Comment thread src/uu/cp/src/copydir.rs Outdated
"source" => entry.source_relative.quote()
),
));
show!(CpError::CannotOpenForReading(entry.source_relative.clone()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we drop e here, so any other permission-denied cause gets the same fixed text. please add a test in tests/by-util/test_cp.rs covering the new variant.

Comment thread src/uu/cp/src/cp.rs Outdated
Comment thread src/uucore/src/lib/features/backup_control.rs
Comment thread src/uucore/src/lib/mods/error.rs
Comment thread src/uucore/src/lib/mods/error.rs
@xtqqczze
xtqqczze marked this pull request as draft October 5, 2026 22:22
@xtqqczze
xtqqczze force-pushed the cold-error-size branch 2 times, most recently from 7d30714 to aacd4c6 Compare October 5, 2026 22:34
@xtqqczze xtqqczze changed the title perf: mark error handling functions as cold perf: mark error handling functions as cold and non-inlineable Oct 5, 2026
@xtqqczze
xtqqczze marked this pull request as ready for review October 5, 2026 22:36
Error construction is infrequently executed compared with the normal success paths. Mark these functions with `#[cold]` so the compiler can treat them as unlikely code paths and keep cold code separate from hot code.

Use `#[inline(never)]` to prevent error-handling code from being inlined into their callers, avoiding unnecessary code-size growth and keeping the normal execution paths smaller.
@sylvestre
sylvestre merged commit 9019055 into uutils:main Oct 6, 2026
190 of 191 checks passed
@xtqqczze
xtqqczze deleted the cold-error-size branch October 9, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants