Repository navigation
sort: avoid scratch allocation for stable sorts on 32-bit - #16906
ChrisX101010 wants to merge 4 commits into
Conversation
| // rayon's thread pool which triggers an unreachable trap. | ||
| if settings.stable || settings.unique { | ||
| #[cfg(not(target_os = "wasi"))] | ||
| #[cfg(all(not(target_os = "wasi"), target_pointer_width = "32"))] |
There was a problem hiding this comment.
why only 32-bit? the index tie-break would work everywhere and drop a cfg branch
| #[test] | ||
| #[cfg(all(target_os = "linux", target_pointer_width = "32"))] | ||
| fn test_unique_sort_under_address_space_limit() { | ||
| const MEMORY_LIMIT: u64 = 96 * 1024 * 1024; |
There was a problem hiding this comment.
does this test fail without the fix? please document where 96M / 36*32k come from
Merging this PR will regress 1 benchmark1 warning, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
GNU testsuite comparison: |
|
Thanks, Sylvestre. I checked both points on 20c6423. The index
tie-break now applies on every non-WASI target. The 32-bit guard is
only on the Linux address-space test. WASI keeps its existing
sequential stable sort.
The test now names the 96 MiB RLIMIT_AS and constructs 36 MiB of input
from a fixed pair of 16-byte records. The inline comment documents the
original i686 observation: the input fits for an ordinary sort, while
the old stable sorter tried to allocate about 24 MiB of scratch space.
I checked the latest i686 GNU and musl CI logs: the patched test still
fails on both, with the harness reporting a broken pipe while feeding
stdin. That does not establish the child’s failure cause or a passing
patched versus failing baseline result. I’d feed the same fixture from
a file first so the exit status and stderr are visible, then compare
both revisions under the same limit.
CodSpeed also reports a 3.13% CPU regression on
sort_unique_utf8_locale, alongside reduced memory use. I haven’t
marked that as resolved.
…On Fri, 27 Nov 2026 06:12:33 -0800, Sylvestre Ledru ***@***.***> wrote:
@sylvestre commented on this pull request.
> @@ -2748,7 +2748,10 @@ fn sort_by<'a>(unsorted: &mut Vec<Line<'a>>, settings: &GlobalSettings, line_dat
// WASI does not support threads, so use non-parallel sort to avoid
// rayon's thread pool which triggers an unreachable trap.
if settings.stable || settings.unique {
- #[cfg(not(target_os = "wasi"))]
+ #[cfg(all(not(target_os = "wasi"), target_pointer_width = "32"))]
why only 32-bit? the index tie-break would work everywhere and drop a cfg branch
> @@ -343,6 +343,24 @@ fn test_ignore_case_orders_punctuation_after_letters() {
.stdout_is("A\na\n_\n");
}
+#[test]
+#[cfg(all(target_os = "linux", target_pointer_width = "32"))]
+fn test_unique_sort_under_address_space_limit() {
+ const MEMORY_LIMIT: u64 = 96 * 1024 * 1024;
does this test fail without the fix? please document where 96M / 36*32k come from
--
Reply to this email directly or view it on GitHub:
#16906 (review)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
On 32-bit Linux, sort -u can run out of memory when allocating temporary scratch space for stable sorting under tight address-space limits. This change preserves the existing relative order of equal keys using par_sort_unstable_by with an index tie-breaker, avoiding the extra chunk-sized allocation.
Refs #16850. Split out from #16901 as requested in review.