Repository navigation
Generate SetParentInImmediateChildren to avoid ForEachChild closures - #65798
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Jake Bailey (jakebailey) wants to merge 1 commit into
Conversation
…ild closures
Parser.finishNodeWithEnd previously set child.Parent via
node.ForEachChild(p.setParentFromContext), invoking an indirect closure
and writing p.currentParent twice for every AST node including leaf
tokens that have no children.
Generate ast.SetParentInImmediateChildren from tools/scripts/tsc/ast.json
with a leaf-token fast path and direct per-kind child assignment, and
call it from Parser.overrideParentInImmediateChildren.
benchstat (-pgo=off, parent vs commit, n=6):
goos: linux
goarch: amd64
│ old │ new │
│ sec/op │ sec/op vs base │
Tsc/vscode 6.562 ± 4% 6.537 ± 2% ~ (p=0.240 n=6)
Tsc/mui-docs 3.854 ± 1% 3.889 ± 2% ~ (p=0.394 n=6)
geomean 5.029 5.042 +0.27%
│ old │ new │
│ B-rss │ B-rss vs base │
Tsc/vscode 4.674Gi ± 4% 4.735Gi ± 2% ~ (p=0.818 n=6)
Tsc/mui-docs 2.219Gi ± 7% 2.151Gi ± 7% ~ (p=0.589 n=6)
geomean 3.221Gi 3.191Gi -0.90%
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the parser’s parent-assignment optimization.
No open issues 🎉
1 file not reviewed
tsc/internal/ast/setparent_generated.go: Generated file
What changed in this PR
Optimizes immediate-child parent assignment in the TypeScript parser by replacing visitor closures with generated, node-kind-specific code.
Changes:
- Adds a generated parent-setting helper with a fast return for tokens.
- Removes the parser’s parent-setting closure and associated state.
- Extends the AST generator to produce the new helper.
| File | Description |
|---|---|
tsc/internal/parser/parser.go |
Uses the generated helper and removes closure state. |
tsc/internal/ast/setparent_generated.go |
Implements direct parent assignment for immediate children. |
tools/scripts/tsc/generate-go-ast.ts |
Generates and registers the new Go output. |
Review effort: Balanced
Member
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This branch has not been deployed
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.
This speeds up parent setting, which previously did extra work for nodes which did not actually have children to walk into, and avoids some indirect calling. Also kills the last parser closure.