Repository navigation
Conversation
rintaro
requested review from
hamishknight,
hborla and
nkcsgexi
as code owners
September 18, 2026 18:11
Member
Author
|
@swift-ci Please test |
rintaro
marked this pull request as draft
September 22, 2026 05:42
rintaro
force-pushed
the
perf-parser-16-lookahead-ranges
branch
from
September 23, 2026 03:13
f7d88c5 to
5cd2106
Compare
Member
Author
|
@swift-ci Please test |
Member
Author
|
@swift-ci Please test Windows |
rintaro
force-pushed
the
perf-parser-16-lookahead-ranges
branch
from
September 23, 2026 03:22
5cd2106 to
832894e
Compare
Member
Author
|
@swift-ci Please test |
Member
Author
|
@swift-ci Please test Windows |
1 similar comment
Member
Author
|
@swift-ci Please test Windows |
Every parse records how far it looked ahead for each node it might later reuse, in a dictionary in the parsing arena keyed by node identity, which is a hash insertion per node. Only an incremental reparse reads those lengths, so a parse that is not part of one does the work for nothing. `Parser` takes `collectsLookaheadRanges`, which defaults to true so that a caller holding a `Parser` of its own keeps recording. What opts out is `Parser.parse(source:)` and its buffer sibling, which are not entry points for incremental parsing. A tree they return can still be handed to `IncrementalParseTransition(previousTree:edits:lookaheadRanges:)`, but none of its nodes will be reused. A parse handed a `parseTransition` records whatever it was asked, since the reparse after it decides reuse from what it records. The default matters more than it looks. `IncrementalParseLookup` never reuses a node it has no recorded length for, so a parse that records none yields a correct tree, no diagnostic, and no reuse at all downstream. `SyntaxTreeManager` in sourcekit-lsp drives a chain of `Parser`s directly, since `parseIncrementally` takes no language features, and with the flag defaulted the other way nothing its first parse produced would ever be reusable. `testLookaheadRangesAreRecordedForAParserDrivenDirectly` is that chain in miniature. A full parse that records reserves the arena's table against the byte count first, since a node is registered roughly every 90 bytes of source and the table would otherwise grow and rehash through the parse.
rintaro
force-pushed
the
perf-parser-16-lookahead-ranges
branch
from
October 8, 2026 23:28
832894e to
3d58210
Compare
Member
Author
|
@swift-ci Please test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every parse used to register each node that might later be reused in a dictionary keyed by node identity, which is a hash insertion per node. In
Parser.parse(source:), nothing reads the dictionary and it was wasted.Parsernow takescollectsLookaheadRanges. TheparseIncrementallyentry points, which return the ranges, pass true; the entry points that return only a tree leave it false. A parse given aparseTransitionrecords regardless of what the caller asked, because what it hands on is what the next reparse decides reuse from, andIncrementalParseLookupwill not reuse a node it has no range for — so a caller drivingParserdirectly would otherwise lose reuse for everything that parse produced, with a correct tree and no diagnostic to show for it.A parse that does collect reserves the table against the source's byte count first, since a node is registered roughly every 90 bytes and the table would otherwise grow and rehash through the parse; an incremental parse skips the reserve, because the table it inherits replaces it.
Measured against
main(1f995c7), 2.5-2.9% instruction reduction, but 0.1% for deliberately corrupted sample source, which spends its parse recovering rather than registering nodes.One behavior change:
Parser.lookaheadRangesispublic internal(set), and a caller drivingParserdirectly for a full parse now finds it empty unless it passescollectsLookaheadRanges: true. An incremental parse is not affected.