Repository navigation
Description
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
Activity
amcasey commentedon Mar 27, 2020
Jack Murphy (@rightisleft) Thanks for the detailed report!
Some initial observations, before I look at your CPU profile:
srcandtest- that would probably save you a bunch of time on every rebuild.extendedDiagnosticsoutput 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--extendedDiagnosticson the command line, rather than in the tsconfig?amcasey commentedon Mar 27, 2020
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?).
amcasey commentedon Mar 27, 2020
Are the files in
database/migrationsenormous? The names make me think they might be generated.rightisleft commentedon Mar 27, 2020
5: In regards to database/migrations - they are generated by TypeORM. We have 54 migration files. A majority of them are sql code wrapped as strings.
rightisleft commentedon Mar 27, 2020
I've tried excluding both the migrations and test folders... i see about a .5 second increase in complication times.
amcasey commentedon Mar 27, 2020
Ah, I see what I was missing - 76 types is for an incremental compilation. Can you please try a couple of tests that explicitly defeat that?
rightisleft commentedon Mar 28, 2020
amcasey commentedon Mar 30, 2020
Thanks! Those numbers make a lot more sense. Something's going on with "Program time" - it's nearly always (much) smaller than "Check time". Your files aren't on a network share or something, are they?
amcasey commentedon Mar 30, 2020
My reading of those numbers is that a lot of time is spent reading the code, but it's not very complicated. TS itself, for example, has roughly 1 type for every 3 lines of code and uses a lot more memory. The cache sizes are also quite small.
Is there some way you could exclude the generated files, as an experiment? You might need to insert some casts to
anyordeclaresome constants to handle the missing symbols.amcasey commentedon Mar 30, 2020
According to the profile you attached, something like 24% of time is spent in f/l/stat calls (!). Of course, that was for an incremental build, which spends a lot of time on freshness checks, but still...
rightisleft commentedon Apr 1, 2020
Andrew Casey (@amcasey)
1: How would you like me to exclude generated files?
2: Would you like another cpu profile with incremental builds turned off?
amcasey commentedon Apr 1, 2020
Jack Murphy (@rightisleft)
amcasey commentedon Apr 10, 2020
Jack Murphy (@rightisleft) I'm keenly aware that the world is upside down right now, but I thought I'd ping this thread in case it's just fallen through the cracks.
amcasey commentedon Sep 3, 2020
Please open a new issue and tag me if you'd like to revisit this.
mmahalwy commentedon Nov 8, 2021
Andrew Casey (@amcasey) I do have a similar problem but probably due to have large 1 file is. See:
amcasey commentedon Nov 10, 2021
m.e. (@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)?