Skip to content

chore: change to toSorted instead of slice().sort #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

nnmrts
Copy link
Contributor

@nnmrts nnmrts commented Jul 26, 2025

Summary

This changes all occurrences of the pattern array.slice().sort() to array.toSorted() with the cost of having to bump the tsconfig's target and lib to "es2023" and the supported Node.js version to ">=20.0.0".

Related issue, if any:

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed
  • Release notes in next-minor.md or next-major.md have been added, if needed

Does this PR introduce a breaking change?

Yes

Users need to adapt their environment or transpiler from "es2017" to "es2023" and from Node.js 16 to 20.

Bundle impact

Status File Size 1 Difference
M src/array/alphabetical.ts 167 -4 (-2%)
M src/array/sort.ts 112 -4 (-3%)

Footnotes

  1. Function size includes the import dependencies of the function.

@nnmrts nnmrts requested a review from aleclarson as a code owner July 26, 2025 08:38
@radashi-bot
Copy link

radashi-bot commented Jul 26, 2025

Benchmark Results

Name Current Baseline Change
alphabetical ▶︎ with ascending order 2,305,588.25 ops/sec ±0.55% 2,402,813.3 ops/sec ±0.47% 🔗 🐢 -4.05%
alphabetical ▶︎ with descending order 2,309,946.66 ops/sec ±2.4% 2,398,856.92 ops/sec ±0.49% 🔗 🐢 -3.71%
sort ▶︎ with ascending order 2,508,515.59 ops/sec ±0.53% 2,617,500.78 ops/sec ±0.76% 🔗 🐢 -4.16%
sort ▶︎ with descending order 2,536,385.94 ops/sec ±0.56% 2,664,829.84 ops/sec ±0.54% 🔗 🐢 -4.82%

Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure.

@nnmrts nnmrts changed the title change to toSorted instead of slice().sort chore: change to toSorted instead of slice().sort Jul 26, 2025
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.

3 participants