Replace ForEachReturnStatement closure with direct kind-switched walk#4239
Open
mds-ant wants to merge 2 commits into
Open
Replace ForEachReturnStatement closure with direct kind-switched walk#4239mds-ant wants to merge 2 commits into
mds-ant wants to merge 2 commits into
Conversation
ForEachReturnStatement allocated a self-referential closure on every call and recursed via ForEachChild, which dispatches through an interface and visits expression-typed children (conditions, initializers) that the closure immediately rejects. Rewrite as a self-recursive package-level function that switches on Kind and recurses only into the statement-typed children of each construct. This removes the per-call closure allocation, the ForEachChild interface dispatch, and the wasted visits to non-statement children. The set of traversed kinds is unchanged.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors ForEachReturnStatement to use explicit, kind-specific traversal (instead of generic ForEachChild) and adds a small helper to traverse NodeLists, with an added nil guard for safety.
Changes:
- Rewrote
ForEachReturnStatementto explicitly recurse through statement-bearing node kinds. - Added
forEachReturnStatementInNodeListto traverse statement lists (*NodeList). - Added a
nilguard to avoid panics when called with a nil node.
Member
You omitted the comparison, no? I suspect this might be within noise when end to end |
Member
|
This is probably fine, but an alternative approach would have been to copy the parent pointer code where we just reuse the closure, I think. |
Member
|
@typescript-bot perf test this |
|
@DanielRosenwasser Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
lspComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Context
ForEachReturnStatementallocated a self-referential closure on every call and recursed viaForEachChild, which dispatches through an interface and visits expression-typed children (conditions, initializers) that the closure immediately rejects.This PR
This PR rewrites
ForEachReturnStatementas a self-recursive package-level function that switches onKindand recurses only into the statement-typed children of each construct. This removes the per-call closure allocation, theForEachChildinterface dispatch, and the wasted visits to non-statement children. The set of traversed kinds is unchanged.This PR was assisted by Claude Code.
Performance
hyperfine benchmark:
Memory allocations (measured using
--noEmit --singleThreaded --diagnostics):