Skip to content

TypeScript --watch initial compilation several times slower for the same codebase since 2.8 #25018

Closed
@devuo

Description

@devuo

TypeScript Version: 2.9.2, >= 2.8

Search Terms: Slow compilation, Slow watch

Code
The initial watch compilation time issue is not directly reproducible under OSX, and is only manifested when executed under a Docker container. Thus for easier debugging and demonstration of the issue, I've created a repo with all the required code that reproduces the issue and contains additional supporting documentation such as v8 profiling. See the following repository for a reproducible step-by-step instructions and code.

https://github.com/devuo/typescript-slow-watch-bug

Expected behavior:
Initial --watch compilation times should take about the same time the same time as they did in 2.7. Here's how --watch looks like in 2.7 for the codebase referred above:

node_modules/.bin/tsc --watch --extendedDiagnostics

08:31:33 - Starting compilation in watch mode...
Files:                   61
Lines:                62744
Nodes:               273576
Identifiers:          98075
Symbols:              80280
Types:                29130
Memory used:        125488K
I/O Read time:        0.19s
Parse time:           0.77s
Program time:         1.97s
Bind time:            0.48s
Check time:           1.62s
transformTime time:   0.02s
printTime time:       0.02s
Emit time:            0.04s
commentTime time:     0.00s
Source Map time:      0.00s
I/O Write time:       0.01s
Total time:           4.12s
08:31:37 - Compilation complete. Watching for file changes.

Actual behavior:
Initial --watch compilation times for the same codebase take many times under >= 2.8 than they did in 2.7. Exact initial compilation times since 2.8 appears to depend on the number of files being scanned under the root project directory. Here's how --watch looks like in 2.9 for the same codebase above:

node_modules/.bin/tsc --watch --extendedDiagnostics

08:27:10 - Starting compilation in watch mode..
08:27:43 - Found 0 errors. Watching for file changes.
Files:                   61
Lines:                63371
Nodes:               279942
Identifiers:          99371
Symbols:              79865
Types:                30108
Memory used:        140212K
I/O Read time:        0.18s
Parse time:           0.70s
Program time:        30.17s
Bind time:            0.45s
Check time:           1.80s
transformTime time:   0.02s
commentTime time:     0.00s
Source Map time:      0.00s
I/O Write time:       0.01s
printTime time:       0.05s
Emit time:            0.05s
Total time:          32.47s

Here's where 2.9 appears to spend most of its time during a profiling session:

   ticks parent  name
  22067   67.1%  /lib/ld-musl-x86_64.so.1
  15181   68.8%    LazyCompile: *getAccessibleFileSystemEntries /app/node_modules/typescript/lib/tsc.js:3502:52
  15161   99.9%      LazyCompile: ~getAccessibleSortedChildDirectories /app/node_modules/typescript/lib/tsc.js:3303:67
  15161  100.0%        LazyCompile: ~watchChildDirectories /app/node_modules/typescript/lib/tsc.js:3120:39
  15161  100.0%          LazyCompile: ~updateChildWatches /app/node_modules/typescript/lib/tsc.js:3115:36
  15152   99.9%            LazyCompile: ~createDirectoryWatcher /app/node_modules/typescript/lib/tsc.js:3098:40

Compare with 2.7:

   ticks parent  name
   1831   35.4%  /usr/local/bin/node
   1667   91.0%    /usr/local/bin/node
    253   15.2%      LazyCompile: ~directoryExists /app/node_modules/typescript/lib/tsc.js:2766:37
    249   98.4%        LazyCompile: ~directoryExists /app/node_modules/typescript/lib/tsc.js:61964:39
    249  100.0%          LazyCompile: ~directoryExists /app/node_modules/typescript/lib/tsc.js:58876:33
    249  100.0%            LazyCompile: ~compilerHost.directoryExists /app/node_modules/typescript/lib/tsc.js:62085:82

Related Issues: #22953

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions