Skip to content

Comments

Use a re-usable Intl.Collator instance for locale compare when possible#1638

Merged
jeffvli merged 2 commits intojeffvli:developmentfrom
eramdam:dmn/shared-collator-compare
Feb 3, 2026
Merged

Use a re-usable Intl.Collator instance for locale compare when possible#1638
jeffvli merged 2 commits intojeffvli:developmentfrom
eramdam:dmn/shared-collator-compare

Conversation

@eramdam
Copy link
Contributor

@eramdam eramdam commented Feb 2, 2026

After opening #1637, I tried to run a git bisect to see when and the UI seemed slower since ~1.3.0. Bisect lead me to this commit that added natural sorting. Unfortunately, using localeCompare on a lot of items in an array isn't free because the JS engine re-creates a new instance of Intl.Collator for every item.

This PR fixes that by setting up a re-usable instance of Intl.Collator() which yields a ~84% speed improvement (when sorting 1,000 items).

@vercel
Copy link

vercel bot commented Feb 2, 2026

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

Project Deployment Actions Updated (UTC)
feishin Ready Ready Preview, Comment Feb 2, 2026 7:53pm

@eramdam eramdam changed the title Use a re-usable Intl.Collator instance for locale compare Use a re-usable Intl.Collator instance for locale compare when possible Feb 2, 2026
@jeffvli
Copy link
Owner

jeffvli commented Feb 3, 2026

Good find on this! I don't think my library was large enough to notice a meaningful difference when this change was added, but the performance benchmark speaks for itself.

@jeffvli jeffvli merged commit 72fc5be into jeffvli:development Feb 3, 2026
8 of 10 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.

2 participants