fix(tokenizer): avoid temporary source-line pairs by jinchuntan · Pull Request #1113 · 8f4e/8f4e · GitHub
Skip to content

fix(tokenizer): avoid temporary source-line pairs - #1113

Merged
andorthehood merged 1 commit into
8f4e:mainfrom
jinchuntan:fix/tokenizer-line-iteration
Oct 21, 2026
Merged

andorthehood merged 1 commit into
8f4e:mainfrom
jinchuntan:fix/tokenizer-line-iteration

Conversation

@jinchuntan

Copy link
Copy Markdown
Contributor

Fixes #1069.

Walks physical source lines by index instead of allocating a mapped array of line/index pairs. Comment filtering, continuation folding and physical line numbers keep their existing behavior.

Added nine focused cases covering blanks/comments, continuations, quoted semicolons, source preservation and malformed-continuation diagnostics. No snapshots changed.

Validated on Node 24.16.0:

npx nx run-many --targets=test,typecheck --projects=@8f4e/tokenizer,@8f4e/compiler --parallel=1

All 869 tests passed, along with both typechecks and Biome.

Before/after preprocessing outcomes also match for 245 compiler fixtures and eight edge cases. A separate benchmark using the issue's prepared inputs gave these local medians:

Physical lines Before (ms/call) After (ms/call)
1,000 0.090 0.081
10,000 1.059 0.919
100,000 15.202 10.318

Inputs contain 80% instructions, 10% comments and 10% blank lines. Timings cover only foldArgumentContinuationLines(): four warmups, then 11 alternating before/after samples, averaging 20 calls per sample at 1k/10k lines and two at 100k. No timing thresholds were added to tests.

Iterate physical lines directly instead of allocating a mapped array of
line/index pairs. Add focused coverage for filtering, continuation folding,
physical source locations, diagnostics and input preservation.
@irimias57 irimias57 added contributor compiler Compiler, tokenizer, codegen, and language-semantics work labels Oct 19, 2026

@andorthehood andorthehood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the optimization @jinchuntan !

@andorthehood
andorthehood merged commit 2386505 into 8f4e:main Oct 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler Compiler, tokenizer, codegen, and language-semantics work contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid temporary line/index pairs in tokenizer preprocessing

3 participants