Repository navigation
perf(executor): one locale resolution per glob sort (#681) - #689
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 insidestrcoll_posixcmp— O(n log n) resolutions per sort, across 9 sortsites — even though the result is constant for the whole sort.
Fix
locale::collation_is_c()+sort_collated[/_reverse]: resolve onceper 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 tiesdistinct 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_ALLbehaves 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%).LANG=en_US.UTF-8): unchanged by design (livecollation preserved) — earlier −1% runs were measuring the slow
path on both sides.
Verification
locale::sort_collated_matches_per_comparison_sort(forward +reverse on collation-tricky data).
glob_diff.sh34/34 under default env ANDLC_ALL=C;casearm_diff.sh30/30 underLC_ALL=C.cargo test --lib596/596.Test-level 1 NEW / 1 DISAPPEARED, both in the
known-nondeterministic
part_080coproc family (both pass inisolation on branch). No regression.
6295367, only rubash[patch]switched): failure sets byte-identical (8=8).