Skip to content

Replace quadratic array sorting with stable merge sort - #296

Merged
ctate merged 2 commits into
mainfrom
codex/array-sort-parity
Sep 12, 2026
Merged

Replace quadratic array sorting with stable merge sort#296
ctate merged 2 commits into
mainfrom
codex/array-sort-parity

Conversation

@ctate

@ctate ctate commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Replace quadratic insertion sorting with stable bottom-up merge sorting for the supported Array.sort, Array.toSorted, and Uint8Array.toSorted forms. 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 for sort, fresh copies for toSorted, 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 743f05b in 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, and NEXT_DIST_DIR=.next-check pnpm check passed for the docs workspace.

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.
@vercel

vercel Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Sep 12, 2026 8:42pm UTC

@ctate
ctate changed the base branch from codex/sandbox-command-files to main September 12, 2026 20:59
@ctate
ctate merged commit 4b241f7 into main Sep 12, 2026
21 checks passed
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