-
Notifications
You must be signed in to change notification settings - Fork 701
[api-extractor] Optimize the analysis type-check pass #5891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmichon-msft
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
dmichon-msft:api-extractor-optimize-typecheck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,13 +200,6 @@ export class Collector { | |
| throw new Error('DtsRollupGenerator.analyze() was already called'); | ||
| } | ||
|
|
||
| // This runs a full type analysis, and then augments the Abstract Syntax Tree (i.e. declarations) | ||
| // with semantic information (i.e. symbols). The "diagnostics" are a subset of the everyday | ||
| // compile errors that would result from a full compilation. | ||
| for (const diagnostic of this._program.getSemanticDiagnostics()) { | ||
| this.messageRouter.addCompilerDiagnostic(diagnostic); | ||
| } | ||
|
|
||
| const sourceFiles: readonly ts.SourceFile[] = this.program.getSourceFiles(); | ||
|
|
||
| if (this.messageRouter.showDiagnostics) { | ||
|
|
@@ -294,6 +287,25 @@ export class Collector { | |
| } | ||
| } | ||
|
|
||
| // Report compiler diagnostics, but only for the source files that are reachable from the entry | ||
| // point: the files that contribute an analyzed declaration, plus the intermediate re-export | ||
| // files that were visited while resolving exports. API Extractor analyzes the compiler's `.d.ts` | ||
| // outputs and (by default) does not enable `skipLibCheck`, so running `getSemanticDiagnostics()` | ||
| // across the entire program would bind-and-check every transitively reachable declaration file, | ||
| // including deep dependencies that are not part of the API surface. Scoping the diagnostics to | ||
| // the analyzed files avoids that cost while still surfacing every error that pertains to the | ||
| // exported API. (Binding, which the analysis relies on, happens eagerly for all files when the | ||
| // type checker is created, so this does not affect the analysis itself.) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we tighten this a bit? It is repeating the exact same sentence from your other check above, reads like slop (trying to explain every exact nuance, no mental model of what the audience would reasonably already know or what questions they would care about) |
||
| const diagnosticSourceFiles: Set<ts.SourceFile> = this.astSymbolTable.collectAnalyzedSourceFiles(); | ||
| for (const sourceFile of nonExternalSourceFiles) { | ||
| diagnosticSourceFiles.add(sourceFile); | ||
| } | ||
| for (const sourceFile of diagnosticSourceFiles) { | ||
| for (const diagnostic of this._program.getSemanticDiagnostics(sourceFile)) { | ||
|
Comment on lines
+290
to
+304
|
||
| this.messageRouter.addCompilerDiagnostic(diagnostic); | ||
| } | ||
| } | ||
|
|
||
| // Here, we're collecting reference directives from all non-external source files | ||
| // that were encountered while looking for exports, but only those references that | ||
| // were explicitly written by the developer and marked with the `preserve="true"` | ||
|
|
||
11 changes: 11 additions & 0 deletions
11
common/changes/@microsoft/api-extractor/optimize-typecheck_2026-07-21-22-06-48.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "comment": "Improve analysis performance by scoping compiler diagnostics to the source files that are reachable from the entry point, rather than type-checking the entire program. As a result, compiler errors are now only reported for declarations that contribute to the analyzed API surface.", | ||
| "type": "minor", | ||
| "packageName": "@microsoft/api-extractor" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/api-extractor", | ||
| "email": "dmichon-msft@users.noreply.github.com" | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there any validation that this optimization actually improved anything (e.g. runtime against a real repo)?