perf: use packed arrays with binary search for lookups#14
Merged
sindresorhus merged 4 commits intosindresorhus:mainfrom Feb 18, 2026
Merged
perf: use packed arrays with binary search for lookups#14sindresorhus merged 4 commits intosindresorhus:mainfrom
sindresorhus merged 4 commits intosindresorhus:mainfrom
Conversation
Replace boolean chain functions for isAmbiguous and isWide with flat [start, end] arrays and O(log n) binary search. Reduces minified bundle size by 25% (5,582 → 4,170 bytes). Ref: sindresorhus/string-width#71
This was referenced Feb 15, 2026
Owner
|
|
Move the packed array + binary search logic into scripts/build.js so lookup.js is properly generated instead of hand-edited.
sindresorhus
requested changes
Feb 15, 2026
Contributor
Author
|
Addressed! |
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.
Problem
The independent lookup functions in
lookup.jsuse long boolean chains (179 and 136 conditions forisAmbiguousandisWiderespectively), which produce a large minified output and require O(n) linear scans.Changes
scripts/build.jsto generate flat[start, end]pair arrays with a sharedisInRangebinary search function for all independent lookup functionsBundle size
Minified: 5,582 → 4,170 bytes (-25%)
Performance
O(n) boolean chains → O(log n) binary search. Benchmarked with 10M iterations per test:
isAmbiguous(worst case)isWide(worst case)isAmbiguous(hit)getCategory(mixed)Ref: sindresorhus/string-width#71