Skip to content

TS3.0 conditional slow performance with rollup: no program reuse with "redirect" source files #27207

Closed
@AlexLandau

Description

@AlexLandau

TypeScript Version: 3.0.1 through 3.1.0-dev.20180918

This bug does not manifest in TypeScript 2.9.2.

Search Terms:
Rollup slow performance perf
Program structure reuse
redirectInfo

Code

A repo reproducing the problem: https://github.com/AlexLandau/ts3-rollup-perf-bug

Note: This only happens when a feature in the TypeScript compiler is triggered that offers special handling for identical source files. In our case, we see this due to particular combinations of dependencies at certain versions.

I originally saw this in a proprietary monorepo where, upon switching from TypeScript 2.9.2 to 3.0.1, individual packages were taking up to 25 minutes (each) to build with rollup and rollup-plugin-typescript2. After investigating, I believe typescript is the party not working as intended here, rather than rollup or the plugin. I think rollup is just hitting a particular performance regression over and over again, in a way that tsc wouldn't.

Expected behavior:
I expect the performance to be similar to that of 2.9.2.

In terms of what I've seen debugging the code: I expect tryReuseStructureFromOldProgram() to indicate that the program can be reused within rollup after it is first initialized.

Actual behavior:
In codebases where this is triggered, the performance of rollup is approximately 5-10 times worse than 2.9.2.

I see tryReuseStructureFromOldProgram() always indicating that the program cannot be reused due to this check looking at the redirectInfo for the source files. At the point of failure, some of the relevant values are:

newSourceFile.fileName: /Users/alandau/repos/rollup-ts3-perf-bug/node_modules/@types/uglify-js/node_modules/source-map/source-map.d.ts
oldSourceFile.fileName: /Users/alandau/repos/rollup-ts3-perf-bug/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts
oldSourceFile.redirectInfo.unredirected.fileName: /Users/alandau/repos/rollup-ts3-perf-bug/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts

Playground Link: N/A

Related Issues:
This PR introduced the redirectInfo construct in play here: #16274

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions