fix(@angular/build): skip semantic diagnostics for declaration files#33400
fix(@angular/build): skip semantic diagnostics for declaration files#33400arturovt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the AOT compilation process by moving the check for declaration files (sourceFile.isDeclarationFile) to occur before retrieving semantic diagnostics. This avoids unnecessary processing and profiling for declaration files, which do not contain semantic or template diagnostics. There are no review comments, so I have no feedback to provide.
|
I don't think this holds for |
Declaration files don't produce semantic or template diagnostics, so calling getSemanticDiagnostics() on them was just wasted work. Move the isDeclarationFile guard to before that call so .d.ts files are skipped entirely.
2be4035 to
2eef0c7
Compare
|
Since getSemanticDiagnostics(sourceFile) already appears to fast-return for .d.ts files under skipLibCheck, this change looks like an extra short-circuit in front of an existing short-circuit. I’m not seeing evidence of any win here, but we do take on extra code paths and another embedded assumption about TS diagnostic behavior. Unless there’s profiling showing this matters, I’d wouldn’t recommend moving forward with this change. |
|
@atscott Measured on a real app (build time ~50s, ~N .d.ts files in node_modules, "N" because I don't know how many of them, when I log "continue" in that if-condition, it kills my terminal). NG_DIAGNOSTICS_TOTAL dropped from ~16s → ~12.9s (~19%). While TS does return Also, DURATION[NG_DIAGNOSTICS_SEMANTIC] and other |
|
That performance difference seems likely due to build time variance. I modified the Angular build performance tracker to log individual durations for every getSemanticDiagnostics call. I then compared the unpatched (baseline) and patched compilations of the web application with parallel TypeScript compilation disabled ( Results Summary
Key Findings1. Call Count is Correctly ReducedThe patch correctly skips declaration files before calling 2. TypeScript Fast Path makes Calls Extremely CheapWhen
3. Absolute Savings are NegligibleSkipping 1,238 calls saved a total of 16.8 milliseconds ( While the patch is technically correct in avoiding redundant calls, the actual performance benefit is in the range of milliseconds, not seconds. The change does not hurt, but it does not provide the claimed speedup. |
Declaration files don't produce semantic or template diagnostics, so calling getSemanticDiagnostics() on them was just wasted work. Move the isDeclarationFile guard to before that call so .d.ts files are skipped entirely.