Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexLandau opened this issue Sep 18, 2018 · 1 comment · Fixed by #27483
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@AlexLandau
Copy link

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

@sheetalkamat
Copy link
Member

This seems to be introduced because of tsbuild and it setting resolvedPath to the redirected target path

oldSourceFile.fileName
"c:/temp/ts3-rollup-perf-bug/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts"
oldSourceFile.originalFileName
"c:/temp/ts3-rollup-perf-bug/node_modules/@types/uglify-js/node_modules/source-map/source-map.d.ts"
oldSourceFile.path
"c:/temp/ts3-rollup-perf-bug/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts"
oldSourceFile.resolvedPath
"c:/temp/ts3-rollup-perf-bug/node_modules/@types/uglify-js/node_modules/source-map/source-map.d.ts"

@sheetalkamat sheetalkamat self-assigned this Sep 28, 2018
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 1, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.2 milestone Oct 1, 2018
sheetalkamat added a commit that referenced this issue Oct 1, 2018
sheetalkamat added a commit that referenced this issue Oct 1, 2018
@sheetalkamat sheetalkamat added the Fixed A PR has been merged for this issue label Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants