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

Slow compilation time for a hello world program (7/8 seconds) #39342

Closed
anisg opened this issue Jun 30, 2020 · 5 comments
Closed

Slow compilation time for a hello world program (7/8 seconds) #39342

anisg opened this issue Jun 30, 2020 · 5 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@anisg
Copy link

anisg commented Jun 30, 2020

TypeScript Version: 3.9.5

Issue:
I created a simple hello world program, and it took 3s to compile with --skipLibCheck, and 7/8s without. is there a way to improve compile time?
output of my terminal:

➜  cat hello.ts
console.log('hello world');
➜  time tsc --skipLibCheck --extendedDiagnostics hello.ts
Files:                         77
Lines:                      42747
Nodes:                     186757
Identifiers:                67158
Symbols:                    44908
Types:                         80
Instantiations:                 0
Memory used:               69869K
Assignability cache size:       0
Identity cache size:            0
Subtype cache size:             0
Strict subtype cache size:      0
I/O Read time:              0.01s
Parse time:                 0.85s
ResolveTypeReference time:  0.01s
ResolveModule time:         0.04s
Program time:               0.96s
Bind time:                  0.56s
Check time:                 0.01s
transformTime time:         0.01s
commentTime time:           0.00s
I/O Write time:             0.00s
printTime time:             0.02s
Emit time:                  0.02s
Total time:                 1.56s
tsc --skipLibCheck --extendedDiagnostics hello.ts  3.45s user 0.09s system 187% cpu 1.889 total

Additional info:
OS: Windows 10
Intel Core i7-8565U CPU @ 1.80GHZ / 16GB RAM / SSD SATA
Terminal: WSL 2 (ubuntu)
Node version: v14.4.0

Expected behavior:
0.1s compilation.

Actual behavior:
3/4s second compilation, without skipLibCheck it goes to 7/8s.

Notes:

  • when I compile this program with deno (deno run hello.ts), it takes 0.5s, which is good! is there a way to have something close to deno with tsc? maybe by using a v8 snapshot as they did?

Related Issues:

Search Terms:

  • slow compilation
  • improve startup time
  • v8 snapshot
@anisg anisg changed the title Slow compilation time for a hello world program Slow compilation time for a hello world program (7/8 seconds) Jun 30, 2020
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jun 30, 2020
@RyanCavanaugh
Copy link
Member

What other files/folders are in this directory? 77 other files implies something else is going on here

@DanielRosenwasser
Copy link
Member

You can diagnose the issue with the guidelines here: https://github.com/microsoft/TypeScript/wiki/Performance#investigating-issues

@anisg
Copy link
Author

anisg commented Jun 30, 2020

Thanks for your reply.

Indeed, there is a node_modules and a package.json in one of its parent directories (where my hello world is in /root/gitlab/contest/test/hello.ts, package.json is in /root/gitlab/contest). I forgot it was called automatically!

the package.json just have @types/node as dependencies:

{
  "dependencies": {
    "@types/node": "^13.13.12"
  }
}

I still think its a lot of compilation time just to have @types/node. Is there any thing I can do to improve it, or am I out of luck?

output with --listFiles flag:

➜  time tsc --extendedDiagnostics hello.ts --listFiles
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es5.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2016.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.dom.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.webworker.importscripts.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.scripthost.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.core.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.collection.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.generator.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.iterable.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.promise.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.proxy.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.reflect.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.symbol.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2016.array.include.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.object.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.string.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.intl.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.intl.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.promise.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2018.regexp.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es2020.bigint.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.esnext.intl.d.ts
hello.ts
/root/gitlab/contest/node_modules/@types/node/globals.d.ts
/root/gitlab/contest/node_modules/@types/node/assert.d.ts
/root/gitlab/contest/node_modules/@types/node/async_hooks.d.ts
/root/gitlab/contest/node_modules/@types/node/buffer.d.ts
/root/gitlab/contest/node_modules/@types/node/child_process.d.ts
/root/gitlab/contest/node_modules/@types/node/cluster.d.ts
/root/gitlab/contest/node_modules/@types/node/console.d.ts
/root/gitlab/contest/node_modules/@types/node/constants.d.ts
/root/gitlab/contest/node_modules/@types/node/crypto.d.ts
/root/gitlab/contest/node_modules/@types/node/dgram.d.ts
/root/gitlab/contest/node_modules/@types/node/dns.d.ts
/root/gitlab/contest/node_modules/@types/node/domain.d.ts
/root/gitlab/contest/node_modules/@types/node/events.d.ts
/root/gitlab/contest/node_modules/@types/node/fs.d.ts
/root/gitlab/contest/node_modules/@types/node/http.d.ts
/root/gitlab/contest/node_modules/@types/node/http2.d.ts
/root/gitlab/contest/node_modules/@types/node/https.d.ts
/root/gitlab/contest/node_modules/@types/node/inspector.d.ts
/root/gitlab/contest/node_modules/@types/node/module.d.ts
/root/gitlab/contest/node_modules/@types/node/net.d.ts
/root/gitlab/contest/node_modules/@types/node/os.d.ts
/root/gitlab/contest/node_modules/@types/node/path.d.ts
/root/gitlab/contest/node_modules/@types/node/perf_hooks.d.ts
/root/gitlab/contest/node_modules/@types/node/process.d.ts
/root/gitlab/contest/node_modules/@types/node/punycode.d.ts
/root/gitlab/contest/node_modules/@types/node/querystring.d.ts
/root/gitlab/contest/node_modules/@types/node/readline.d.ts
/root/gitlab/contest/node_modules/@types/node/repl.d.ts
/root/gitlab/contest/node_modules/@types/node/stream.d.ts
/root/gitlab/contest/node_modules/@types/node/string_decoder.d.ts
/root/gitlab/contest/node_modules/@types/node/timers.d.ts
/root/gitlab/contest/node_modules/@types/node/tls.d.ts
/root/gitlab/contest/node_modules/@types/node/trace_events.d.ts
/root/gitlab/contest/node_modules/@types/node/tty.d.ts
/root/gitlab/contest/node_modules/@types/node/url.d.ts
/root/gitlab/contest/node_modules/@types/node/util.d.ts
/root/gitlab/contest/node_modules/@types/node/v8.d.ts
/root/gitlab/contest/node_modules/@types/node/vm.d.ts
/root/gitlab/contest/node_modules/@types/node/worker_threads.d.ts
/root/gitlab/contest/node_modules/@types/node/zlib.d.ts
/root/gitlab/contest/node_modules/@types/node/base.d.ts
/root/gitlab/contest/node_modules/@types/node/ts3.2/fs.d.ts
/root/gitlab/contest/node_modules/@types/node/ts3.2/util.d.ts
/root/gitlab/contest/node_modules/@types/node/ts3.2/globals.d.ts
/root/gitlab/contest/node_modules/@types/node/ts3.2/index.d.ts
Files:                         77
Lines:                      42747
Nodes:                     186757
Identifiers:                67158
Symbols:                    55373
Types:                      15238
Instantiations:              9066
Memory used:               91057K
Assignability cache size:    3689
Identity cache size:            1
Subtype cache size:             0
Strict subtype cache size:      0
I/O Read time:              0.06s
Parse time:                 0.80s
ResolveTypeReference time:  0.03s
ResolveModule time:         0.04s
Program time:               0.97s
Bind time:                  0.53s
Check time:                 2.28s
transformTime time:         0.01s
commentTime time:           0.00s
I/O Write time:             0.00s
printTime time:             0.02s
Emit time:                  0.02s
Total time:                 3.81s
tsc --extendedDiagnostics hello.ts --listFiles  7.58s user 0.31s system 175% cpu 4.487 total

when I move the script to another folder (e.g /tmp), I have a better compilation time (2.3s).

➜ time tsc --skipLibCheck --extendedDiagnostics hello.ts --listFiles
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.es5.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.dom.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.webworker.importscripts.d.ts
/usr/local/share/.config/yarn/global/node_modules/typescript/lib/lib.scripthost.d.ts
hello.ts
Files:                          6
Lines:                      24818
Nodes:                     111228
Identifiers:                40850
Symbols:                    24674
Types:                         80
Instantiations:                 1
Memory used:               46120K
Assignability cache size:       0
Identity cache size:            0
Subtype cache size:             0
Strict subtype cache size:      0
I/O Read time:              0.01s
Parse time:                 0.78s
ResolveTypeReference time:  0.00s
Program time:               0.80s
Bind time:                  0.38s
Check time:                 0.02s
transformTime time:         0.01s
commentTime time:           0.00s
I/O Write time:             0.00s
printTime time:             0.02s
Emit time:                  0.02s
Total time:                 1.21s
tsc --skipLibCheck --extendedDiagnostics hello.ts --listFiles  2.47s user 0.11s system 162% cpu 1.585 total

Is there anything I can do to improve that?

@DanielRosenwasser
Copy link
Member

You can set the "types" field to [] which should stop TypeScript from automatically sucking in all @types/ folders unless you import them. I'll update the Performance page to mention this too.

@DanielRosenwasser
Copy link
Member

Here's the new section: Controlling @types Inclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants