TypeScript: tsc compilation slow on moderate sized project
TypeScript Version: 3.9.0-dev.20200326
Search Terms:
tsc slow compilation, tsc memory, tsc slow Program time, tsc Program time
Code
I’m trying to debug why my typescript compiler is taking 9-13 seconds to recompile. This impacts ts-node and development drastically.
typescript version: ^3.X.X
tsconfig.json:
{
"compilerOptions": {
"extendedDiagnostics": true,
"target": "es6",
"lib": ["es2017"],
"module": "commonjs",
"emitDeclarationOnly": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"incremental": true,
"noResolve": false,
"noEmitOnError": false,
"noImplicitAny": true,
"declaration": true,
"sourceMap": true,
"outDir": "dist/",
"moduleResolution": "node",
"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
],
"exclude": [
"node_modules"
]
}
npx tsc --listFiles --generateCpuProfile profile
Files: 732 Lines: 364288 Nodes: 1133413 Identifiers: 417612 Symbols: 236577 Types: 76 Instantiations: 0 Memory used: 330244K Assignability cache size: 0 Identity cache size: 0 Subtype cache size: 0 Strict subtype cache size: 0 I/O Read time: 2.51s Parse time: 3.77s ResolveTypeReference time: 0.33s ResolveModule time: 2.91s Program time: 9.86s Bind time: 1.39s Total time: 11.25s
File List Here: https://pastebin.com/zX7TpM2x
Generated CPU Profile Here: https://gist.github.com/rightisleft/d3c77fe2c643ba4c7832a94209f53ef2
Expected behavior:
This is a mid sized project, it should have a 1-3 second compile time
Actual behavior:
Compile takes anywhere from 9-14 seconds per line change
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (11 by maintainers)
@mmahalwy I find that performance tracing is the most effective way to investigate excessive check time. Can you please give that a shot and file a new issue with the results (assuming you don’t figure it out yourself from the trace)?
Are the files in
database/migrations
enormous? The names make me think they might be generated.Now that I’ve looked at your file list, I’d guess there’s no reason to use project references, given that you appear to have only two test files (which, presumably, are not enormous?).
@rightisleft Thanks for the detailed report!
Some initial observations, before I look at your CPU profile:
src
andtest
- that would probably save you a bunch of time on every rebuild.extendedDiagnostics
output with zero in those places. That actually looks like the output from--diagnostics
, rather than--extendedDiagnostics
(which would be a bug on us). Could you please try again with--extendedDiagnostics
on the command line, rather than in the tsconfig?