Skip to content

two lines in an interface cause a build time explosion [strictGenericChecks] #18257

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
emmanueltouzery opened this issue Sep 5, 2017 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@emmanueltouzery
Copy link

emmanueltouzery commented Sep 5, 2017

TypeScript Version: Tested on 2.5.2 and 2.6.0-dev.20170904

Code

The code is there:
https://github.com/emmanueltouzery/prelude.ts/tree/5c33c1eeeea7234506e54331d06590e2feb9b00d

To build it you can just run npm install && tsc. It's about 1800 LOCs of typescript.

On my (old) machine, if I build it as-is with 2.5 or 2.6-dev I get a ~5s build time. If I uncomment in src/IMap.ts lines 29 and 30, however, the build time explodes. On 2.5 I didn't bother waiting but it would be a long, long, long time. On 2.6-dev the speed is much better but the build time still explodes from 5 seconds to 35 seconds.

The two lines are:

     mapValuesStruct<V2>(fn:(v:V)=>V2): IMap<K,V2>;
     mapValues<V2>(fn:(v:V)=>V2&WithEquality): IMap<K,V2>;

And they are implemented in src/HashMap.ts with:

    map<K2,V2>(fn:(k:K&WithEquality, v:V)=>[K2&WithEquality,V2&WithEquality]): HashMap<K2,V2> {
        return this.mapStruct(fn);
    }

    mapValuesStruct<V2>(fn:(v:V)=>V2): HashMap<K,V2> {
        return this.hamt.fold(
            (acc: HashMap<K,V2>, value: V, key: K&WithEquality) =>
                acc.putStruct(key,fn(value)), HashMap.empty());
    }

When I implement the interface, I change the return type to a more specific one, which is as far as I'm aware, legal.

Expected behavior:
Uncommenting these two lines of code shouldn't cause the build time to increase sevenfold. Maybe the code is wrong, but then I should get a compilation error or a warning, not an increased build time.

If I put in the tsconfig.json:
"noStrictGenericChecks": true

then the performance issue goes away completely even with the lines uncommented.

@emmanueltouzery emmanueltouzery changed the title two lines in an interface cause a build time explosion (probably improved generics typecheck issue) two lines in an interface cause a build time explosion [strictGenericChecks] Sep 5, 2017
@mhegazy mhegazy added the Bug A bug in TypeScript label Sep 5, 2017
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Sep 6, 2017
@mhegazy mhegazy added this to the TypeScript 2.5.3 milestone Sep 6, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants