Files
react-native-devtools-frontend/third_party/typescript
Tim van der Lippe 32377e38e6 Optimize tsc calls by skipping lib checks for is_debug=true
Our invocations to `tsc` are slower than expected. Following the
performance guide on the TypeScript wiki [1], we can apply some
optimizations for our build.

The most promising optimization is skipping the checks for all
declaration files. The ts_library is heavily depended on the
declaration files, as we use project references behind the scenes.
Moreover, we use several "global" declaration files that are large.

Since we have strict control over the declaration files that are
generated, we can omit the lib checks during development. For safety,
we will remaining checking the libs on a release build, to catch
potential issues. Therefore, condition the skipping on the `is_debug`
flag in the typescript.gni definition.

Before this change:

$ NINJA_SUMMARIZE_BUILD=1 autoninja -C out/Default
/Users/tvanderlippe/Projects/depot_tools/ninja -C out/Default -j 10 -d stats
ninja: Entering directory `out/Default'
[1 processes, 1/1 @ 3.4/s : 0.294s ] Regenerating ninja files
[1 processes, 254/254 @ 3.2/s : 80.175s ] STAMP obj/test/test.stamp
metric           	count 	avg (us) 	total (ms)
.ninja parse     	4     	14789.8 	59.2
canonicalize str 	18000 	0.1     	2.5
canonicalize path	18174 	0.1     	1.3
lookup node      	18172 	0.1     	1.9
.ninja_log load  	2     	4535.5  	9.1
.ninja_deps load 	2     	215.0   	0.4
node stat        	7954  	5.1     	40.9
depfile load     	2     	293.0   	0.6
StartEdge        	256   	1557.4  	398.7
FinishCommand    	255   	258.4   	65.9

path->node hash load 0.64 (3914 entries / 6151 buckets)
    Longest build steps:
           1.6 weighted s to build (26 items) gen/test/unittests/front_end/ui/ui-tsconfig.json, gen/test/unittests/front_end/ui/ui-tsconfig.json.tsbuildinfo, ... (8.3 s elapsed time)
           1.6 weighted s to build (44 items) gen/test/unittests/front_end/common/common-tsconfig.json, gen/test/unittests/front_end/common/common-tsconfig.json.tsbuildinfo, ... (10.5 s elapsed time)
           1.6 weighted s to build (26 items) gen/test/unittests/front_end/sdk/sdk-tsconfig.json, gen/test/unittests/front_end/sdk/sdk-tsconfig.json.tsbuildinfo, ... (4.9 s elapsed time)
           1.7 weighted s to build (5 items) gen/test/unittests/front_end/dom_extension/dom_extension-tsconfig.json, gen/test/unittests/front_end/dom_extension/dom_extension-tsconfig.json.tsbuildinfo, ... (8.1 s elapsed time)
           1.7 weighted s to build (17 items) gen/test/unittests/front_end/platform/platform-tsconfig.json, gen/test/unittests/front_end/platform/platform-tsconfig.json.tsbuildinfo, ... (7.9 s elapsed time)
           1.8 weighted s to build (8 items) gen/test/unittests/front_end/browser_sdk/browser_sdk-tsconfig.json, gen/test/unittests/front_end/browser_sdk/browser_sdk-tsconfig.json.tsbuildinfo, ... (4.0 s elapsed time)
           1.8 weighted s to build (74 items) gen/front_end/common/common-tsconfig.json, gen/front_end/common/common-tsconfig.json.tsbuildinfo, ... (8.1 s elapsed time)
           2.5 weighted s to build (5 items) gen/test/unittests/front_end/issues/issues-tsconfig.json, gen/test/unittests/front_end/issues/issues-tsconfig.json.tsbuildinfo, ... (3.7 s elapsed time)
           3.2 weighted s to build (179 items) gen/front_end/ui/ui-tsconfig.json, gen/front_end/ui/ui-tsconfig.json.tsbuildinfo, ... (25.8 s elapsed time)
           4.5 weighted s to build (170 items) gen/front_end/sdk/sdk-tsconfig.json, gen/front_end/sdk/sdk-tsconfig.json.tsbuildinfo, ... (32.4 s elapsed time)
    Time by build-step type:
           0.0 s weighted time to generate 1 .conf.js files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 1 .mjs.map files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 1 .mjs files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 4 .json files (0.2 s elapsed time sum)
           0.0 s weighted time to generate 19 .svg files (0.3 s elapsed time sum)
           0.1 s weighted time to generate 42 .png files (0.8 s elapsed time sum)
           0.1 s weighted time to generate 65 .stamp files (0.8 s elapsed time sum)
           0.7 s weighted time to generate 1 .grd files (1.8 s elapsed time sum)
           2.0 s weighted time to generate 67 .js files (14.4 s elapsed time sum)
          77.3 s weighted time to generate 53 .d.ts files (506.2 s elapsed time sum)
    80.2 s weighted time (524.4 s elapsed time sum, 6.5x parallelism)
    254 build steps completed, average of 3.17/s

After this change:

$ NINJA_SUMMARIZE_BUILD=1 autoninja -C out/Default
/Users/tvanderlippe/Projects/depot_tools/ninja -C out/Default -j 10 -d stats
ninja: Entering directory `out/Default'
[1 processes, 1/1 @ 3.9/s : 0.260s ] Regenerating ninja files
[1 processes, 248/248 @ 5.9/s : 41.903s ] STAMP obj/test/test.stamp
metric           	count 	avg (us) 	total (ms)
.ninja parse     	4     	14791.8 	59.2
canonicalize str 	18000 	0.1     	2.5
canonicalize path	18174 	0.1     	1.4
lookup node      	18172 	0.1     	1.8
.ninja_log load  	2     	2128.0  	4.3
.ninja_deps load 	2     	53.5    	0.1
node stat        	6248  	5.4     	33.5
depfile load     	2     	400.5   	0.8
StartEdge        	250   	1496.1  	374.0
FinishCommand    	249   	195.0   	48.5

path->node hash load 0.64 (3914 entries / 6151 buckets)
    Longest build steps:
           0.8 weighted s to build (17 items) gen/test/unittests/front_end/text_utils/text_utils-tsconfig.json, gen/test/unittests/front_end/text_utils/text_utils-tsconfig.json.tsbuildinfo, ... (5.7 s elapsed time)
           0.9 weighted s to build (44 items) gen/test/unittests/front_end/common/common-tsconfig.json, gen/test/unittests/front_end/common/common-tsconfig.json.tsbuildinfo, ... (5.7 s elapsed time)
           0.9 weighted s to build (14 items) gen/front_end/browser_sdk/browser_sdk-tsconfig.json, gen/front_end/browser_sdk/browser_sdk-tsconfig.json.tsbuildinfo, ... (1.8 s elapsed time)
           0.9 weighted s to build (74 items) gen/front_end/common/common-tsconfig.json, gen/front_end/common/common-tsconfig.json.tsbuildinfo, ... (3.7 s elapsed time)
           1.0 weighted s to build (5 items) gen/front_end/issues/issues-tsconfig.json, gen/front_end/issues/issues-tsconfig.json.tsbuildinfo, ... (1.9 s elapsed time)
           1.0 weighted s to build (26 items) gen/test/unittests/front_end/sdk/sdk-tsconfig.json, gen/test/unittests/front_end/sdk/sdk-tsconfig.json.tsbuildinfo, ... (2.0 s elapsed time)
           1.0 weighted s to build (5 items) gen/test/unittests/front_end/issues/issues-tsconfig.json, gen/test/unittests/front_end/issues/issues-tsconfig.json.tsbuildinfo, ... (2.0 s elapsed time)
           1.1 weighted s to build (8 items) gen/test/unittests/front_end/browser_sdk/browser_sdk-tsconfig.json, gen/test/unittests/front_end/browser_sdk/browser_sdk-tsconfig.json.tsbuildinfo, ... (2.4 s elapsed time)
           2.8 weighted s to build (179 items) gen/front_end/ui/ui-tsconfig.json, gen/front_end/ui/ui-tsconfig.json.tsbuildinfo, ... (14.2 s elapsed time)
           4.4 weighted s to build (170 items) gen/front_end/sdk/sdk-tsconfig.json, gen/front_end/sdk/sdk-tsconfig.json.tsbuildinfo, ... (14.8 s elapsed time)
    Time by build-step type:
           0.0 s weighted time to generate 1 .mjs files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 1 .conf.js files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 1 .mjs.map files (0.0 s elapsed time sum)
           0.0 s weighted time to generate 4 .json files (0.2 s elapsed time sum)
           0.0 s weighted time to generate 19 .svg files (0.3 s elapsed time sum)
           0.1 s weighted time to generate 42 .png files (0.7 s elapsed time sum)
           0.1 s weighted time to generate 65 .js files (1.0 s elapsed time sum)
           0.1 s weighted time to generate 61 .stamp files (0.5 s elapsed time sum)
           0.8 s weighted time to generate 1 .grd files (1.8 s elapsed time sum)
          40.8 s weighted time to generate 53 .d.ts files (222.1 s elapsed time sum)
    41.9 s weighted time (226.7 s elapsed time sum, 5.4x parallelism)
    248 build steps completed, average of 5.92/s

[1]: https://github.com/microsoft/TypeScript/wiki/Performance#skipping-dts-checking

R=jacktfranklin@chromium.org
CC=​yangguo@chromium.org

Bug: 1011811
Change-Id: I9fc368db2d26fd11d62e8f30d7fcb04bfe44dcc1
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2193571
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2020-05-11 12:49:17 +00:00
..
2019-11-25 11:52:53 +00:00
2019-11-25 11:52:53 +00:00

GN TypeScript integration

To integrate gn with TypeScript, this directory contains a ts_library action to compile TypeScript and JavaScript sources with the TypeScript compiler tsc.

To use the action, import the typescript.gni file:

import("../../third_party/typescript/typescript.gni")

After importing, you can now use the ts_library action to define a GN task that compiles with tsc:

ts_library("my_typescript_library") {
  sources = [
    "foo.ts",
  ]
}

ts_library("my_javascript_library") {
  sources = [
    "bar.js",
  ]
}

ts_library("my_mixed_library") {
  sources = [
    "typescript.ts",
    "javascript.js",
  ]
}

The sources will be compiled with tsc and generate corresponding output in the gen folder in the out directory.

To depend on other ts_libraries, specify the deps:

ts_library("my_user_library") {
  sources = [
    "dependent.ts",
  ]

  deps = [
    ":my_mixed_library",
  ]
}

deps use the same notation as GN deps. Therefore, ninja will parallelize compilation of ts_library dependencies.

A ts_library either needs to specify sources, deps or both.

For tests compiled with ts_library, set testonly = true:

ts_library("my_test_library") {
  testonly = true,
  sources = [
    "my_library_test.ts",
  ]

  deps = [
    "../../../../front_end/my_library",
  ]
}

Compiling with testonly = true will include the type definitions for Node, Chai and Mocha.

To instruct Ninja to execute the ts_library task, make sure that there is a dependency chain from /BUILD.gn (or test/*/BUILD.gn) to the ts_library in question.

Implementation details

A ts_library task will generate a tsconfig.json based on /tsconfig.base.json and write it to disk in the gen directory. Ater that, it will instruct tsc to compile the project based on the tsconfig.json.

All deps are desugared to project references. tsc will not recursively compile dependencies, Ninja handles that.

Since Ninja does not recompile unchanged actions, all ts_library actions generate corresponding .d.ts files which specify the public API's of the sources, as well as the .tsbuildinfo for efficient recompilation with tsc.

There are several global .d.ts files added to every ts_library. The GLOBAL_TYPESCRIPT_DEFINITION_FILES list in ts_library.py contains the list of all definition files. These files must also be listed as inputs in typescript.gni.

Legacy: For legacy reasons, all non-testonly outputs are also copied to resources/inspector in the out directory.