microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.78k stars 12.46k forks source link

Seeking Guidance: Significant performance regression within editor when upgrading typescript versions in large monorepo #60311

Open mitch1995 opened 1 day ago

mitch1995 commented 1 day ago

Acknowledgement

Comment

Context

Upon upgrading from typescript version 5.4.2 to 5.5.2 we are seeing a large performance regression within our local editor (vscode). We are seeking guidance on what might be causing this regression and how we can find a solution to allow us to proceed with the upgrade. We are not seeing any performance impact when running the actual typescript compilation build (e.g. running tsc -b project-references.tsconfig.json).

We have tested this in multiple versions, such as 5.6.0 and 5.7.0, and are still seeing the same regression. I have also tested typescript version 5.4.5 and have not experienced any regressions, which makes me believe the regression occurred somewhere between 5.4.5 and 5.5.2.

Typescript settings

We are using the same typescript settings mentioned in a previous ticket that we opened (https://github.com/microsoft/TypeScript/issues/59780).

Regression

We are seeing this regression locally within our IDEs (we predominately use vscode). Our monorepo has many sub-packages that are separate TS projects. We have tooling in place that randomly selects and tests the elapsed time it takes a TS project to show type definitions (by looking at the updateOpen elapsed time). For simplicity's sake, I will focus on a single TS project where we are seeing a large regression.

Typescript Version 5.4.2 Typescript Version 5.5.2 Percentage Increase
74.29ms 136.64ms +84%

updateOpen: elapsed time (in milliseconds)

Typescript Version 5.4.2 updateOpen: elapsed time (in milliseconds) (mean average): 74.29.

Running tsc -p projectDir/tsconfig.json --extendedDiagnostics produces:

Files:                        28110
Lines of Library:             38866
Lines of Definitions:        814186
Lines of TypeScript:        1834871
Lines of JavaScript:              0
Lines of JSON:                 4507
Lines of Other:                   0
Identifiers:                2834483
Symbols:                    7353123
Types:                      2044340
Instantiations:            14039604
Memory used:               6912809K
Assignability cache size:   2807267
Identity cache size:         844956
Subtype cache size:          158977
Strict subtype cache size:   235064
I/O Read time:               10.16s
Parse time:                   4.05s
ResolveModule time:           8.68s
ResolveTypeReference time:    0.02s
ResolveLibrary time:          0.01s
Program time:                24.66s
Bind time:                    2.32s
Check time:                 116.29s
printTime time:               0.73s
Emit time:                    0.84s
transformTime time:           0.06s
commentTime time:             0.00s
I/O Write time:               0.02s
Total time:                 144.11s

The below are snippets taken from the TS Server logs in vscode:

Info 0     [13:51:34.806] Starting TS Server
Info 40    [13:51:34.941] Starting updateGraphWorker: Project: projectDir/tsconfig.json
Info 54126 [13:52:25.108] Finishing updateGraphWorker: Project: projectDir/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 50167.559082984924ms
Info 54197 [13:52:28.218] Starting updateGraphWorker: Project: projectDir/tsconfig.json
Info 83985[13:52:48.329] Finishing updateGraphWorker: Project: projectDir/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 20111.59362500906ms
Perf 83993[13:52:51.013] 2::updateOpen: elapsed time (in milliseconds) 76179.5956

The below screenshot is from running tsc -p projectDir/tsconfig.json --generateTrace Image

Typescript Version 5.5.2 updateOpen: elapsed time (in milliseconds) (mean average): 136.64

Running tsc -p projectDir/tsconfig.json --extendedDiagnostics produces:

Files:                        28246
Lines of Library:             39135
Lines of Definitions:        820870
Lines of TypeScript:        1834871
Lines of JavaScript:              0
Lines of JSON:                 4507
Lines of Other:                   0
Identifiers:                2843999
Symbols:                    7100120
Types:                      1952998
Instantiations:            15389105
Memory used:               6624656K
Assignability cache size:   2762165
Identity cache size:         845019
Subtype cache size:          158941
Strict subtype cache size:   217035
I/O Read time:               11.47s
Parse time:                   7.54s
ResolveModule time:          12.34s
ResolveTypeReference time:    0.02s
ResolveLibrary time:          0.02s
Program time:                34.61s
Bind time:                    3.01s
Check time:                 108.32s
I/O Write time:               0.01s
printTime time:               0.49s
Emit time:                    0.49s
Total time:                 146.43s

The below are snippets taken from the TS Server logs in vscode:

Info 0    [14:06:01.540] Starting TS Server
Info 48   [14:06:01.705] Starting updateGraphWorker: Project: projectDir/tsconfig.json
Info 12837[14:07:14.662] Finishing updateGraphWorker: Project: projectDir/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 72938.59612500668ms
Info 12850[14:07:17.960] Starting updateGraphWorker: Project: projectDir/tsconfig.json
Info 18115[14:08:07.940] Finishing updateGraphWorker: Project: projectDir/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 49968.97329199314ms
Perf 18116[14:08:10.834] 2::updateOpen: elapsed time (in milliseconds) 129234.7819

The below screenshot is from running tsc -p projectDir/tsconfig.json --generateTrace Image


If you require any additional info, please let me know and I will work on getting it for you

Andarist commented 1 day ago

If you could bisect this to the exact nightly version that introduced this perf degradation that would certainly help to start investigating this