Skip to content

Blink: classify array brackets in one pass - #287

Merged
TomasVotruba merged 1 commit into
ecsphp:mainfrom
gnutix:perf/array-notation-enclosing
Nov 4, 2026
Merged

TomasVotruba merged 1 commit into
ecsphp:mainfrom
gnutix:perf/array-notation-enclosing

Conversation

@gnutix

@gnutix gnutix commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem: for every [, TrailingCommaInMultiline, ArraySyntax/ListSyntax (syntax=long), WhitespaceAfterCommaInArray and StatementIndentation ask which bracket encloses it. arrayNotationEnclosing and arrayNotationInForeachHead answer by scanning back to that bracket, so a large array is quadratic.

Change:

  • WhitespaceAfterCommaInArray and StatementIndentation follow the brackets as they walk forward (arrayNotationTracker).
  • TrailingCommaInMultiline and arrayNotationToLong walk backward. They try a backward scan of at most 256 tokens, and only when that isn't enough run one forward pass over the file (arrayNotationScan).
  • The other callers keep the backward scans.

Result: a 40k-token file with one large array: 1.09 s → 0.19 s with all rules. On a private 8.8k-file codebase, TrailingCommaInMultiline: 630 → 330 ms.

Tests: a new test compares the new code with the backward scans at every index of 20,000 random token streams. Existing tests pass, and the private codebase still has 0 diffs. On 28k files, main and this branch give the same output for each of these rules, and for all rules together.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y1vvcRhpVMjWLC4U5j78Xp

Some array rules walked back to the enclosing bracket for every "[", which
is quadratic in a large array. They now follow the brackets in one forward
pass, or use a short backward scan. The output is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gnutix
gnutix force-pushed the perf/array-notation-enclosing branch from 0dfcabd to 95ad218 Compare November 4, 2026 17:37
@gnutix gnutix changed the title Blink: classify array brackets in one pass, not one backward scan each Blink: classify array brackets in one pass Nov 4, 2026
@TomasVotruba
TomasVotruba merged commit 3f052f0 into ecsphp:main Nov 4, 2026
20 of 21 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

Thanks 👍

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