Skip to content

Avoid copying input for identifier lookahead - #834

Merged
ydah merged 1 commit into
masterfrom
fix/identifier-lookahead-copy
Nov 2, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/identifier-lookahead-copy

Conversation

@ydah

@ydah ydah commented Oct 29, 2026

Copy link
Copy Markdown
Member

identifier_colon? copied the remaining input for every identifier, causing quadratic cumulative copying. Duplicate the scanner instead, sharing its input while keeping the lookahead cursor independent.

Parser#parse benchmarks, median of five runs on Ruby 4.0.6 (arm64 macOS):

Input Before After
2,000 rules 40.8 ms 28.7 ms
16,000 rules 683.7 ms 308.6 ms
Ruby 3.4.0 parse.y 63.0 ms 28.4 ms

Synthetic inputs use short rNNNNN: TOKEN TOKEN; rules. Ruby's parse.y uses its standard id2token.rb preprocessing. For 16,000 rules, cumulative suffix copying drops from 8.06 GB to zero.

@ydah
ydah merged commit fc86c74 into master Nov 2, 2026
45 checks passed
@ydah
ydah deleted the fix/identifier-lookahead-copy branch November 2, 2026 01:27
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