Skip to content

uucore: use embedded English locale without probing the locales dir - #16907

Merged
sylvestre merged 4 commits into
uutils:mainfrom
TheNetherWatcher:perf/locale-embedded-english
Nov 27, 2026
Merged

sylvestre merged 4 commits into
uutils:mainfrom
TheNetherWatcher:perf/locale-embedded-english

Conversation

@TheNetherWatcher

Copy link
Copy Markdown
Contributor

Part of #16862 (the "noop for embedded english" half).

When the detected locale is en-US (also when LANG is unset, C or POSIX), setup_localization now builds the bundle from the embedded English files and returns before looking for the locales directory. English is always embedded by build.rs, so this skips the current_exe() readlink, the is_dir/canonicalize probes and the reads of uucore/en-US.ftl and <util>/en-US.ftl. It only takes this path when the utility has its own embedded strings, so invoked names like [ keep the existing handling. Other locales are unchanged.

Measured on Linux aarch64 (release builds of echo/ls with an installed share/locales layout, LANG unset):

before after
echo hi syscalls (strace -c) 93 68
ls /tmp syscalls 108 83
readlink / .ftl opens 8 / 2 0 / 0
echo hi (hyperfine -N, 3000 runs) 991 ± 80 µs 930 ± 72 µs

One behaviour change: a distro that patches en-US.ftl on disk would no longer see its changes picked up for English. I asked about this on the issue; happy to gate it differently if that matters.

Tested with cargo test -p uucore --all-features --lib locale and the test, ls, echo and cksum integration tests (786 passed), plus a manual check that LANG=fr_FR.UTF-8 ls --help is still French.

@oech3

This comment was marked as resolved.

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
// English is embedded at build time, so there is no need to look for
// the locales directory (a readlink and several stats) or read files
if locale == DEFAULT_LOCALE
&& get_embedded_locale(&format!("{p}/{DEFAULT_LOCALE}.ftl")).is_some()

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.

the same get_embedded_locale(&format!("{p}/{DEFAULT_LOCALE}.ftl")) is done again a few lines below, could be computed once, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, done in 8ef60ef: it's computed once and used by both checks.

@TheNetherWatcher

Copy link
Copy Markdown
Contributor Author

Added one in 5738abd: test_english_does_not_touch_locales_dir in tests/test_localization_and_colors.rs runs echo, ls and cksum --help under strace -e trace=file with LANG=en_US.UTF-8 and fails if any path contains locales. Same skip-if-no-strace pattern as the ls strace tests. On Linux it passes with this PR and fails on main (statx(".../uu/echo/locales"), readlinkat(...)).

Comment thread tests/test_localization_and_colors.rs Outdated
#[cfg(target_os = "linux")]
#[test]
fn test_english_does_not_touch_locales_dir() {
for utility in ["echo", "ls", "cksum"] {

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in d0be592: the test now runs only true --help.

Comment thread tests/test_localization_and_colors.rs Outdated
Comment on lines +309 to +311
/// English strings are embedded, so an English run must not look for or read
/// locale files (see #16862)
#[cfg(target_os = "linux")]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in d0be592, with feature = "true" (singular, as the cfg needs). Checked on Linux: it fails with the main branch locale code and passes on this branch.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@sylvestre
sylvestre merged commit 8efadca into uutils:main Nov 27, 2026
193 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@codspeed

codspeed Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 3.11%

1 warning, 1 note

⚠️ 123 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 2 improved benchmarks
✅ 413 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation ls_recursive_deep_tree[(200, 2)] 3.1 ms 3 ms +3.21%
⚡ CPU Simulation tee_stdin_file[10000000] 365.5 µs 354.8 µs +3.01%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing TheNetherWatcher:perf/locale-embedded-english (d0be592) with main (ab69b86)2

Open in CodSpeed

Footnotes

  1. 70 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 (5b84528) during the generation of this report, so ab69b86 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

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.

3 participants