Repository navigation
uucore: use embedded English locale without probing the locales dir - #16907
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
| // 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() |
There was a problem hiding this comment.
the same get_embedded_locale(&format!("{p}/{DEFAULT_LOCALE}.ftl")) is done again a few lines below, could be computed once, no?
There was a problem hiding this comment.
Yes, done in 8ef60ef: it's computed once and used by both checks.
|
Added one in 5738abd: |
| #[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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Done in d0be592: the test now runs only true --help.
| /// 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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
|
GNU testsuite comparison: |
|
Thanks for your PR |
Merging this PR will improve performance by 3.11%1 warning, 1 note
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Part of #16862 (the "noop for embedded english" half).
When the detected locale is
en-US(also whenLANGis unset,CorPOSIX),setup_localizationnow builds the bundle from the embedded English files and returns before looking for the locales directory. English is always embedded bybuild.rs, so this skips thecurrent_exe()readlink, theis_dir/canonicalizeprobes and the reads ofuucore/en-US.ftland<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/lswith an installedshare/localeslayout,LANGunset):echo hisyscalls (strace -c)ls /tmpsyscalls.ftlopensecho hi(hyperfine -N, 3000 runs)One behaviour change: a distro that patches
en-US.ftlon 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 localeand thetest,ls,echoandcksumintegration tests (786 passed), plus a manual check thatLANG=fr_FR.UTF-8 ls --helpis still French.