Skip to content

perf(executor): one locale resolution per glob sort (#681) - #689

Merged
caomengxuan666 merged 1 commit into
masterfrom
perf/issue681-glob-sort
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
perf/issue681-glob-sort

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

perf(executor): one locale resolution per glob sort (#681)

What

Slice (b) of the glob sort residual: every glob-sort comparison paid
collate_locale_name's three env lookups + name mapping inside
strcoll_posixcmp — O(n log n) resolutions per sort, across 9 sort
sites — even though the result is constant for the whole sort.

Fix

locale::collation_is_c() + sort_collated[/_reverse]: resolve once
per sort; byte order under the C/POSIX family, host collation
otherwise. Result-identical by construction (under C collation
strcoll_posixcmp(a, b) == a.cmp(b) exactly — strcoll never ties
distinct strings, so the tie-break never fires; non-C path runs the
identical comparator). Same env source as before (process env), so
script-set LC_ALL behaves exactly as it did.

GNU: pathexp.c:881 globsort_namecmp / :917 sh_sortglob
(strcoll only for ranges per lib/glob/smatch.c:90-120).

Measured (release, 300 files × 2000 iters, rotated min-of-5)

  • LC_ALL=C: 3.21s → 2.52s (−22%).
  • Default env (LANG=en_US.UTF-8): unchanged by design (live
    collation preserved) — earlier −1% runs were measuring the slow
    path on both sides.

Verification

  • New locale::sort_collated_matches_per_comparison_sort (forward +
    reverse on collation-tricky data).
  • glob_diff.sh 34/34 under default env AND LC_ALL=C;
    casearm_diff.sh 30/30 under LC_ALL=C.
  • cargo test --lib 596/596.
  • Full serial failure-set gate vs master: per-target results match.
    Test-level 1 NEW / 1 DISAPPEARED, both in the
    known-nondeterministic part_080 coproc family (both pass in
    isolation on branch). No regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): failure sets byte-identical (8=8).

Every glob-sort comparison paid collate_locale_name's three env
lookups + mapping inside strcoll_posixcmp. sort_collated[/_reverse]:
resolve once per sort; byte order under C/POSIX, host collation
otherwise. Result-identical (C: strcoll==strcmp exactly; non-C: same
comparator; same env source).

LC_ALL=C 300-file loop -22%. Contract test; batteries 34/34 both
locales.

GNU: pathexp.c:881/917; smatch.c:90-120.
@caomengxuan666
caomengxuan666 merged commit cb4e381 into master Oct 17, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the perf/issue681-glob-sort branch October 17, 2026 01:08
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.

1 participant