Skip to content

Compute token offsets once instead of rescanning from the first token - #322

Merged
ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
fabpot:token-offset-lookup
Sep 27, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
fabpot:token-offset-lookup

Conversation

@fabpot

@fabpot fabpot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

While working on the Symfony LSP server, I found that TokenIterator::currentTokenOffset() was quadratic. This PR fixes it by first computing every token offset. That allows to look up the current index later on.

I've tested it on array{kN?: 'a'|'b'|string, …}:

Keys Before After
200 13.0 ms 7.8 ms
800 155.9 ms 10.0 ms
3,200 2,312 ms 40.9 ms

@ondrejmirtes
ondrejmirtes merged commit 1427af4 into phpstan:2.3.x Sep 27, 2026
61 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you very much! Tagging 2.3.6 right now.

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