Repository navigation
Conversation
Author
@microsoft-github-policy-service agree |
Member
|
TypeScript Bot (@typescript-bot) perf test this |
Contributor
|
Starting jobs; this comment will be updated as builds start and complete.
|
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.
Part of #65830 (implements the two smallest code-level items from the profiling data; benchmark details in this comment).
This PR was authored with AI assistance (OpenCode harness, Qwen4.0 Max Preview, high reasoning) under human direction; the human reviewed the analysis, benchmarks, and diff at each step.
Motivation & Guidance
Motivation:
The user maintains TsUML2 (UML diagrams from TypeScript projects), which recently moved to the native 7.1 API. Profiling the engine-creation floor for that tool produced #65829 and #65830. The user then asked for the cache-free, GC-free, parallelism-free code-level wins to be implemented and benchmarked, and to combine the small ones into a PR.
Guidance:
The user's prompts, in order: "Perf Can we reduce the engine creation floor? Contribute to typescript 7.1?" → "and now perf improvements in code (no cache, no gc, no more cores)" → "Combine the small ones to a pr (benchmark before)". When prompted about the repo's milestone policy, the user chose the issue-comment route first; after reviewing the lean comment draft (and asking to cut a negative-result section as noise: "Isn't the pooling comment just generate noise"), they instructed opening this PR. Benchmark-before was an explicit requirement; a third change that regressed was dropped.
Analysis
CPU/alloc profiling of parse+bind (743k-line declaration-heavy corpus,
--noCheck, data in #65830) showed two patterns of provably no-op work intsc/internal/parser/parser.go:parseContextualModifier/parseAnyContextualModifiercallp.mark()— copying the fullParserState— before checking whether the current token can match. On a mismatch (the common case: every non-accessor class/type member pays two failedget/setprobes) the function immediatelyrewinds: a pure save/restore round-trip with no observable effect. Profile:mark1.45% +rewind2.18% flat CPU.finishNodeWithEnd→overrideParentInImmediateChildrenwalksForEachChildfor every finished node to set parent pointers. All kinds belowast.KindFirstNode(tokens, literals, identifiers, keywords) have no cases in the generatedForEachChilddispatch — the walk visits nothing. These are the majority of nodes in declaration-heavy code. Profile: 5.1% cum.Fix
Two commits, one per pattern:
falsewhen the token cannot match,mark()only on a potential match. Observably identical —mark/rewindhave no side effects beyond state save/restore.node.Kind < ast.KindFirstNode. Conservative: any future leaf kind added aboveKindFirstNodesimply falls through to the existing walk.Benchmarks (interleaved A/B wall-clock medians,
--noEmit --noCheck, no--extendedDiagnostics; noise floor 0.2%; linux-x64, 4 cores, Go 1.27.4; baselinemain@7141cc0):noResolve(n=15)Per-change within-session deltas: (1) −6.4% decl / −1.4% expr; (2) −3.0% decl / neutral expr. Shared host, ±2–3% session noise; combined effect −3 to −5% decl-heavy across sessions.
Alternate considered: pooling the temporary list buffers (
parseListIndex/parseDelimitedList/parseModifiersEx) to cut the allocation churn also identified in #65830. Implemented and benchmarked: +29% regression (sync.Pool victimization under frequent GC; still +4% with GOGC=off), so it was dropped.Tests:
go test ./internal/parser/... ./internal/ast/... ./internal/binder/...pass (parser includes the fuzz seed corpus);gofmtclean; both benchmark corpora (~1M lines) parse exit-0 on every run. No behavior change intended — the changes remove no-op work only.Opened as Draft per CONTRIBUTING: the linked issue has no assigned Milestone yet. Asking maintainers whether this direction is acceptable (and whether #65830 or a split-out issue could be milestoned); happy to run repo perf automation or adjust. If unwanted, feel free to close — the analysis and benchmarks remain in the issue for reference.