Skip to content

Extremely slow compilation; resolving generics? #30781

Closed
@mmorearty

Description

@mmorearty

TypeScript Version: 3.5.0-dev.20190405

Search Terms: slow compilation generics

Code

example.zip

Expected behavior:

Compilation should take a reasonable amount of time

Actual behavior:

On my MacBook Pro, compilation takes 31 seconds before any error messages appear.

I suspect this may have to do with the compiler trying to resolve generic types. A few comments:

  • The code is hard to read, because I had to obfuscate it. Sorry about that.
  • This is a hacked-up version of some of our real code. The real version compiles successfully (unlike this hacked-up one which produces errors). This is based on a TypeScript module we have that takes two minutes to compile. It only has 19,000 lines of .ts files plus 100,000 lines of .d.ts files. Most of our similar-sized modules take about 30 seconds.
  • Take a look at the declaration of create at the bottom of src/sb_by_hr.ts. If you take out all the fancy generics, and instead put export const create = React.createFactory(Component);, compilation takes only 2 seconds.
  • You'll notice that lib/a.d.ts has a fairly large number of type declarations. The declare module "a/dm/ps" section is about 2800 lines of one- or two-line type declarations, and declare module "a/dm/pm" is about 3800. If you delete large chunks of type declarations from either one of those blocks, the compilation times goes down. It seems to go down. For example, if you delete about half of the types from "a/dm/ps", compilation time goes from 31 seconds down to 11.8 seconds. Similarly, if you delete about half of the types from "a/dm/pm", the time goes down to 11 seconds.

Related Issues:

These may or may not be related:

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions