镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Docs on improving compilation speed #10878

Description

With the --watch flag on, a recompile of an existing file generally takes 4 seconds now in our project. This isn't terrible at all, but the wait time has grown since we started using it.

I was wondering what factors affect incremental compilation speed? With TypeScript gaining widespread adoption, I think it'll be very important to developer experience to have a doc page detailing the main contributors to incremental compilation time and ways to improve it.

P.S. Note I meant incremental compilation speed with --watch, not a full recompile.

Activity

  1. StokeMasterJack commented on May 27, 2019

    @StokeMasterJack

    It would be nice to know what types of things can cause a project to compile slowly. For example, if certain language features (large unions?? or generics?? or something else) will result in compilation slow-down, then developers can make decide if trade off is worth it.

    Also, if some 3rd party libs are known to cause major slow downs, that would be good to know also.

    At present, my #1 problem with TypeScript is the slow compile times. And the fact that the IDE is so slow to respond.

  2. WEREMSOFT commented on Jul 27, 2019

    @WEREMSOFT

    I just made a simple script that creates a typescript project, so I can parametrize certain characteristics. Then run tsc.

    The only factor I found so far is file count and line count. Generics didn't do anything. Unions don't do anything.

    Any idea that what else can I test?

  3. StokeMasterJack commented on Jul 28, 2019

    @StokeMasterJack
  4. Pauan commented on Jul 28, 2019

    @Pauan

    WEREMSOFT I recommend adding in tests for this["foo"], in particular like this:

    class Foo {
        private _foo: number = 1;
    }
    
    class Bar extends Foo {
        private _bar: number = 2;
    }
    
    
    class Qux {
        public _qux!: Foo;
    
        public get qux(): this["_qux"] {
            return this._qux;
        }
    }
    
    class Corge extends Qux {
        public _qux!: Bar;
    }
    
    
    const x1: Foo = new Qux().qux;
    const x2: Bar = new Corge().qux;

    We use this pattern a lot. The things to parameterize are how deeply nested the class hierarchy is, how many methods use the this["foo"] type, and how big the classes are (e.g. number of methods/properties).

  5. pimterry commented on Aug 12, 2019

    @pimterry
    Contributor

    One interesting example is this change to the styled-components types, which increased compile time by 20x. Background discussion here: #30663.

    It would be interesting to explore why; I'd love some principles to avoid issues like that in my own code, and tools to find problematic types in general in large codebases. Issues aren't always going to be caused by an obvious dependency upgrade like this.

    #31612 might also be interesting, as another catastrophic performance case that docs/tooling should warn you about, and show you how to avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThe issue relates to how you learn TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions