Skip to content
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

Performance regression in 4.0 with semantics-only createWatchProgram? #40808

Closed
dfreeman opened this issue Sep 28, 2020 · 6 comments · Fixed by #40880
Closed

Performance regression in 4.0 with semantics-only createWatchProgram? #40808

dfreeman opened this issue Sep 28, 2020 · 6 comments · Fixed by #40880
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@dfreeman
Copy link
Contributor

The wiki here has a page that outlines ways to programmatically create a watched build, and suggests that createSemanticDiagnosticsBuilderProgram is likely preferable to createEmitAndSemanticDiagnosticsBuilderProgram for use cases that aren't interested in emit.

The ember-cli-typescript package uses the APIs outlined in that wiki page to integrate typechecking results into Ember CLI builds, and there've been several reports of slower re-checks after a file change from folks that have updated to typescript@4.

TypeScript Version:

  • 3.9.7 (works as expected)
  • 4.0.3 (exhibits slowdown)
  • 4.1.0-dev.20200928 (exhibits slowdown)

Search Terms:

  • createWatchProgram
  • createSemanticDiagnosticsBuilderProgram
  • 4.0 performance

Code

const ts = require('typescript');
const host = ts.createWatchCompilerHost(
  'tsconfig.json',
  { noEmit: true },
  ts.sys,
  ts.createSemanticDiagnosticsBuilderProgram
);

ts.createWatchProgram(host);

Expected behavior:
Re-checks are at least as fast with createSemanticDiagnosticsBuilderProgram as with its counterpart that tracks emit.

Actual behavior:
In a project that takes on the order of 15s to typecheck at startup, re-checking takes less than 1s with the above invocation in 3.9, as well as in 4.0 and the most recent 4.1 nightly when using createEmitAndSemanticDiagnosticsBuilderProgram.

When using createSemanticDiagnosticsBuilderProgram in 4.0 and 4.1, though, re-checking consistently takes around 5s.

@sheetalkamat
Copy link
Member

@dfreeman Can you please provide the repro where this happens.. i ran this on sample and it seems to be using cached diagnostics correctly.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Sep 29, 2020
@dfreeman
Copy link
Contributor Author

dfreeman commented Sep 29, 2020

@sheetalkamat Apologies, the project I mentioned above is private, but I'd (probably foolishly 😄) assumed since it had been reported by several others that it would reproduce easily.

Here's a reproduction repo I put together: https://github.com/dfreeman/ts-40808-perf-demo
(the use of Babel there is incidental; it's just the first thing that popped to mind to give some mass to the typecheck without generating a bunch of code myself)

@sheetalkamat
Copy link
Member

Note that the issue is coming up because of changes in #39122 where we emit build info.
Your code is doing the right thing because you want to emit tsbuildinfo so it can be reused.

@andreyfel
Copy link

@sheetalkamat will the fix be released as a patch fix for 4.0.x series?

@sheetalkamat
Copy link
Member

@DanielRosenwasser is it feasible to take #40880 for 4.0 patch

@DanielRosenwasser
Copy link
Member

Yeah, I think that'd be reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants