Replace quadratic array sorting with stable merge sort - #296
Merged
Conversation
Build the Linux LLVM helper and runtime pack before running both test lanes, and align native cache contracts with the current target policy. Full managed Sandbox gate passed.
Cover sort snapshots, consistent-comparator results, stable ties, and comparator complexity with Node differential fixtures. Document differences from V8 TimSort.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Replace quadratic insertion sorting with stable bottom-up merge sorting for the supported
Array.sort,Array.toSorted, andUint8Array.toSortedforms. Large inputs now take O(n log n) worst-case comparisons, and ordered runs use a linear number of comparator calls. The shared lowering preserves receiver identity forsort, fresh copies fortoSorted, stable ties, and snapshot behavior.Comparator call order and counts still differ from V8 TimSort. Ordered inputs still incur O(n log n) merge-buffer movement; this PR does not add sparse-array support or broaden the existing default-comparator surface. The limitations page states these bounds.
Depends on #295; the PR is based on its branch so the diff contains only sorting changes.
Validation: the full plain and sanitized Sandbox gate passed at
743f05bin 10.8 minutes, including all 16 Sandboxes and local Darwin contracts. Focused C/LLVM differential tests cover stable ordering, undefined placement, comparator mutations/exceptions, snapshots, and comparison bounds against Node 24.15.0. The TS7 order baselines were regenerated, the compiler build passed, andNEXT_DIST_DIR=.next-check pnpm checkpassed for the docs workspace.