Skip to content

Comments

Optimize TextRangeCollection.getItemContaining#11265

Open
Zaczero wants to merge 1 commit intomicrosoft:mainfrom
Zaczero:zaczero/gic
Open

Optimize TextRangeCollection.getItemContaining#11265
Zaczero wants to merge 1 commit intomicrosoft:mainfrom
Zaczero:zaczero/gic

Conversation

@Zaczero
Copy link
Contributor

@Zaczero Zaczero commented Feb 2, 2026

This change improved the performance on openstreetmap-ng codebase by about 1%.

14.6s → 14.4s (-1.1% ± 0.4%)

The generic getIndexContaining supports sparse arrays ((T | undefined)[]) and does extra defensive work. In our hot paths (token/line collections), the array is dense and ordered, so this version:

  • avoids undefined checks and extra branching
  • uses a tight binary search loop
  • adds a cheap “gap” early-out to avoid extra iterations when the position is clearly between adjacent ranges

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