Skip to content

tsc -b parse time is much higher comparing to tsc -p when there is a big d.ts file in node_modules #46147

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
zofiag opened this issue Sep 30, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@zofiag
Copy link

zofiag commented Sep 30, 2021

Bug Report

Using a third-party package with heavy .d.ts files (eg aws-sdk) slows down tsc -b drastically comparing to tsc -p compilation time.

Comparison of the tsc extendedDiagnostics:

  1. tsc -b api/tsconfig.json -w --preserveWatchOutput (or run npm run dev:api:b)
    Much slower after adding a change to the code (eg console.log in a TS file).
Files:                         412
Lines of Library:             8664
Lines of Definitions:       577202
Lines of TypeScript:            34
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Nodes of Library:            23282
Nodes of Definitions:      1689642
Nodes of TypeScript:           137
Nodes of JavaScript:             0
Nodes of JSON:                   0
Nodes of Other:                  0
Identifiers:                626998
Symbols:                    367869
Types:                         261
Instantiations:                276
Memory used:               512906K
Assignability cache size:       29
Identity cache size:             1
Subtype cache size:             10
Strict subtype cache size:       0
I/O Read time:               0.24s
Parse time:                  2.67s
ResolveModule time:          0.09s
ResolveTypeReference time:   0.00s
Program time:                3.18s
Bind time:                   0.93s
Check time:                  0.04s
transformTime time:          0.02s
commentTime time:            0.00s
printTime time:              0.04s
Emit time:                   0.04s
Source Map time:             0.00s
I/O Write time:              0.00s
Total time:                  4.20s
  1. tsc -p api/tsconfig.json -w --preserveWatchOutput (or run npm run dev:api:p)
    Much faster after adding a change to the code (eg console.log in a TS file).
Files:                         412
Lines of Library:             8664
Lines of Definitions:       577202
Lines of TypeScript:            34
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Nodes of Library:            23282
Nodes of Definitions:      1689642
Nodes of TypeScript:           137
Nodes of JavaScript:             0
Nodes of JSON:                   0
Nodes of Other:                  0
Identifiers:                626998
Symbols:                    367869
Types:                         261
Instantiations:                276
Memory used:               513037K
Assignability cache size:       29
Identity cache size:             1
Subtype cache size:             10
Strict subtype cache size:       0
I/O Read time:               0.00s
Parse time:                  0.00s
ResolveModule time:          0.00s
Program time:                0.01s
Bind time:                   0.00s
Check time:                  0.05s
transformTime time:          0.02s
commentTime time:            0.00s
printTime time:              0.05s
Emit time:                   0.05s
Source Map time:             0.00s
I/O Write time:              0.00s
Total time:                  0.11s

🔎 Search Terms

tsc, typescript compiler, build mode, watch mode

🕗 Version & Regression Information

Tested on typescript 3.9.3, 4.4.2, 4.4.3. Same behaviour.

⏯ Playground Link

https://github.com/zofiag/tsc-test - it is a super simple repo project with almost no code, except for the aws-sdk dependency installed that seems to drastically slow down the compilation in build mode.

After cloning the repo, run npm install and:
run npm run dev:api:b for the tsc -b compilation
run npm run dev:api:p for the tsc -p compilation

💻 Code

Project structure:
api/tsconfig.json

{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist"
  },
  "include": [
    "src"
  ],
  "references": [{
      "path": "../libs/shared"
  }]
}

api/src/aws-encryption.ts

import type { KMS } from "aws-sdk";

export class AwsEncryption {
  constructor(private readonly kms: KMS) {}

  encrypt(): Promise<string> {
    return new Promise((resolve, reject) => {
      this.kms.encrypt({ KeyId: "", Plaintext: "" }, (err, data) => {
        if (err) {
          reject(err);
        } else {
          resolve("ok");
        }
      });
    });
  }

  decrypt(): Promise<string> {
    return new Promise((resolve, reject) => {
      this.kms.decrypt({ KeyId: "", CiphertextBlob: "" }, (err, data) => {
        if (err) {
          reject(err);
        } else {
          resolve("ok");
        }
      });
    });
  }
}

shared/tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "lib"
  },
  "include": [
    "src"
  ],
  "references": []
}

tsconfig.base.json

{
  "compilerOptions": {
    "sourceMap": true,
    "strict": true,
    "moduleResolution": "node",
    "module": "commonjs",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es6",
    "lib": [
      "es2020"
    ],
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "forceConsistentCasingInFileNames": true,
    "allowSyntheticDefaultImports": true,
    "allowJs": false,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "declaration": true,
    "composite": true,
    "incremental": true
  },
}

🙁 Actual behavior

Running tsc -b -w is much slower (total time 4.20s) than tsc -p -w (total time 0.11s). The library that seems to be slowing it down is aws-sdk package which is the only dependency in this small repro project.

Why would the same package be parsed much slower in the build mode?

🙂 Expected behavior

Compilation time after adding a change (eg console.log in the TS file) should be nearly the same between tsc -b -w and tsc -p -w when there are no project references specified.

@andrewbranch
Copy link
Member

Duplicate of #45082

@andrewbranch andrewbranch marked this as a duplicate of #45082 Oct 4, 2021
@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Oct 4, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants