Skip to content

Commit 8aa202c

Browse files
Updates.
1 parent 50230a6 commit 8aa202c

File tree

1 file changed

+66
-47
lines changed

1 file changed

+66
-47
lines changed

Performance.md

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ Tests can also be broken into their own project.
4747

4848
You can read up more about project references here. <!-- TODO -->
4949

50-
# Configuring `tsconfig.json`
50+
# Configuring `tsconfig.json` or `jsconfig.json`
5151

52-
Within a `tsconfig.json`, there are two ways to specify files in a project:
52+
TypeScript and JavaScript users can always configure their compilations with a `tsconfig.json` file.
53+
[`jsconfig.json` files can also be used to configure the editing experience](https://code.visualstudio.com/docs/languages/jsconfig) for JavaScript users.
54+
You should always make sure that your configuration files aren't including too many files at once.
55+
56+
Within a `tsconfig.json`, there are two ways to specify files in a project.
5357

5458
* the `files` list
5559
* the `include` and `exclude` lists
@@ -67,7 +71,7 @@ Finally, while `exclude` has some reasonable defaults, certain configurations li
6771

6872
For best practices, we recommend the following:
6973

70-
* Specify only source folders in your project.
74+
* Specify only input folders in your project (i.e. folders whose source code you want to include for compilation/analysis).
7175
* Don't mix source files from other projects in the same folder.
7276
* If keeping tests in the same folder as other source files, give them a distinct name so they can easily be excluded.
7377
* Avoid large build artifacts and dependency folders like `node_modules` in source directories
@@ -93,7 +97,7 @@ Incremental compiles are enabled by default when using the `composite` flag for
9397

9498
## Skipping `.d.ts` Checking
9599

96-
By default, TypeScript performs a full re-check of all `.d.ts` files in a project to find issue and inconsistencies; however, this is typically unnecessary.
100+
By default, TypeScript performs a full re-check of all `.d.ts` files in a project to find issues and inconsistencies; however, this is typically unnecessary.
97101
Most of the time, the `.d.ts` files are known to already work - the way that types extend each other was already verified once, and declarations that matter will be checked anyway.
98102

99103
TypeScript provides the option to skip type-checking of the `.d.ts` files that it ships with (e.g. `lib.d.ts`) using the `skipDefaultLibCheck` flag.
@@ -114,11 +118,11 @@ Make sure that in addition to reading this section, you read up about performanc
114118

115119
## Concurrent Type-Checking
116120

117-
Type-checking typically requires semantic information from other files, and can be relatively expensive compared to other steps like emitting.
118-
Because type-checking can take a little bit longer, it can impact the inner development loop - in other words, you might experience a longer edit/compile/retry cycle, and this might be frustrating.
121+
Type-checking typically requires information from other files, and can be relatively expensive compared to other steps like transforming/emitting code.
122+
Because type-checking can take a little bit longer, it can impact the inner development loop - in other words, you might experience a longer edit/compile/run cycle, and this might be frustrating.
119123

120-
For this reason, some build tools can run type-checking in a concurrent process without blocking emit.
121-
While this means that invalid code can run before TypeScript reports an error in the tool, you'll often see errors in your editor first, and you won't be blocked for as long from running working code.
124+
For this reason, some build tools can run type-checking in a separate process without blocking emit.
125+
While this means that invalid code can run before TypeScript reports an error in your build tool, you'll often see errors in your editor first, and you won't be blocked for as long from running working code.
122126

123127
An example of this in action is the [`fork-ts-checker-webpack-plugin`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) plugin for Webpack, or [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader) which also sometimes does this.
124128

@@ -164,6 +168,14 @@ Isolated file emit can be leveraged by using the following tools:
164168

165169
There are certain ways to get hints of what might be going wrong.
166170

171+
## Disabling Editor Plugins
172+
173+
Editor experiences can be impacted by plugins.
174+
Try disabling plugins (especially JavaScript/TypeScript-related plugins) to see if that fixes any issues in performance and responsiveness.
175+
176+
Certain editors also have their own troubleshooting guides for performance, so consider reading up on them.
177+
For example, Visual Studio Code has its own page for [Performance Issues](https://github.com/microsoft/vscode/wiki/Performance-Issues) as well.
178+
167179
## `extendedDiagnostics`
168180

169181
You can run TypeScript with `--extendedDiagnostics` to get a printout of where the compiler is spending its time.
@@ -192,11 +204,13 @@ Emit time: 0.01s
192204
Total time: 1.75s
193205
```
194206

207+
> Note that `Total time` won't be the sum of all times preceding it, since there is some overlap and some work is not instrumented.
208+
195209
The most relevant information for most users is:
196210

197211
Field | Meaning
198212
--------|---------
199-
`Files` | the number of files that the program is including (use `listFiles` to see what they are).
213+
`Files` | the number of files that the program is including (use `--listFiles` to see what they are).
200214
`I/O Read time` | time spent reading from the file system - this includes traversing `include`'d folders.
201215
`Parse time` | time spent scanning and parsing the program
202216
`Program time` | combined time spent performing reading from the file system, scanning and parsing the program, and other calculation of the program graph. These steps are intermingled and combined here because files need to be resolved and loaded once they're included via `import`s and `export`s.
@@ -205,13 +219,15 @@ Field | Meaning
205219
`transformTime time` | Time spent rewriting TypeScript ASTs (trees that represent source files) into forms that work in older runtimes.
206220
`commentTime` | Time spent calculating comments in output files.
207221
`I/O Write time` | Time spent writing/updating files on disk.
208-
`printTime` | Time spent calculating the string representation of an output file.
209-
210-
<!-- TODO: is this important? Looks identical to printTime
222+
`printTime` | Time spent calculating the string representation of an output file and emitting it to disk.
211223

212-
`Emit time` | ...
224+
Things that you might want to ask given this input:
213225

214-
-->
226+
* Does the number of files/number of lines of code roughly correspond to the number of files in your project? Try running `--listFiles` if not.
227+
* Does `Program time` or `I/O Read time` seem fairly high? [Ensure your `include`/`exclude` settings are configured correctly](#misconfigured-include-and-exclude).
228+
* Do other times seem off? [You might want to file an issue!](#filing-an-issue) Things you can do to help diagnose it might be
229+
* Running with `emitDeclarationOnly` if `printTime` is high.
230+
* Read up instructions on [Reporting Compiler Performance Issues](#reporting-compiler-performance-issues).
215231

216232
## `showConfig`
217233

@@ -235,6 +251,8 @@ The emit is somewhat verbose, so you might want to redirect output to a file.
235251
tsc -p tsconfig.json > resolution.txt
236252
```
237253

254+
If you find a file that shouldn't be present, you may need to look into fixing up your `include`/`exclude` lists in your `tsconfig.json`, or alternatively, you might need to adjust other settings like `types`, `typeRoots`, or `paths`.
255+
238256
## Running `tsc` Alone
239257

240258
Much of the time, users run into slow performance using 3rd party build tools like Gulp, Rollup, Webpack, etc.
@@ -247,14 +265,6 @@ Some questions to keep in mind:
247265
* Does the build tool have *its own configuration* that could be the cause?
248266
* Does the build tool have configuration *for its TypeScript integration* that could be the cause? (e.g. options for ts-loader?)
249267

250-
## Disabling Editor Plugins
251-
252-
Editor experiences can be impacted by plugins.
253-
Try disabling plugins (namely, JavaScript/TypeScript-related plugins) to see if that fixes any issues in performance and responsiveness.
254-
255-
Certain editors also have their own troubleshooting guides for performance, so consider reading up on them.
256-
For example, Visual Studio Code has its own page for [Performance Issues](https://github.com/microsoft/vscode/wiki/Performance-Issues) as well.
257-
258268
## Upgrading Dependencies
259269

260270
Sometimes TypeScript's type-checking can be impacted by computationally intensive `.d.ts` files.
@@ -264,7 +274,7 @@ Upgrading to a newer version of TypeScript (which can be more efficient) or to a
264274
# Common Issues
265275

266276
Once you've trouble-shooted, you might want to explore some fixes to common issues.
267-
If the following solutions don't work, it may be worth [filing an issue](https://github.com/microsoft/TypeScript/issues/new/choose).
277+
If the following solutions don't work, it may be worth [filing an issue](#filing-an-issue).
268278

269279
## Misconfigured `include` and `exclude`
270280

@@ -277,27 +287,6 @@ Problem | Cause | Fix
277287
Hidden dot files (e.g. `.git`) were accidentally included | `"exclude": ["**/node_modules"]` | `"exclude": ["**/node_modules", "**/.*/"]`
278288
Unexpected files are being included. | *`include` was not set* | `"include": ["src"]`
279289

280-
<!--
281-
282-
# Explicit File Lists
283-
284-
Sometimes a `tsconfig.json` can be found by TypeScript, but the command line experience doesn't appear to reflect it.
285-
This is often because users specify explicit files to `tsc`, which will stop TypeScript from seeking out a tsconfig.
286-
287-
```sh
288-
# doesn't look for a tsconfig.json!
289-
tsc main.ts helper.ts
290-
```
291-
292-
As a result, users often run into using the default options with warnings like
293-
294-
```
295-
Cannot find module '{0}'.
296-
Accessors are only available when targeting ECMAScript 5 and higher.
297-
```
298-
299-
-->
300-
301290
# Filing an Issue
302291

303292
If your project is already properly and optimally configured, you may want to [file an issue](https://github.com/microsoft/TypeScript/issues/new/choose).
@@ -308,7 +297,7 @@ They require either no external integration with build tools - they can either b
308297
Codebases that require complex invocations and setups cannot be prioritized.
309298

310299
We understand that this is not always easy to achieve - specifically, because it is hard to isolate the source of a problem within a codebase, and because sharing intellectual property may be an issue.
311-
In some cases, the team will be willing to send a non-disclosure agreement if we believe the issue is highly impactful.
300+
In some cases, the team will be willing to send a non-disclosure agreement (NDA) if we believe the issue is highly impactful.
312301

313302
Regardless of whether a reproduction is possible, following these directions when filing issues will help us provide you with performance fixes.
314303

@@ -347,7 +336,37 @@ Here `./node_modules/typescript/lib/tsc.js` can be replaced with any path to whe
347336

348337
This will generate two files:
349338

350-
* `--trace-ic` will emit to a file of the `isolate-*-*-*.log` (e.g. `isolate-00000176DB2DF130-17676-v8.log`).
339+
* `--trace-ic` will emit to a file of the `isolate-*-*-*.log` (e.g. `isolate-00000176DB2DF130-17676-v8.log`).
351340
* `--generateCpuProfile` will emit to a file with the name of your choice. In the above example, it will be a file named `profile.cpuprofile`.
352341

353-
Both of these files are readable as plain-text, and you can modify them before attaching them as part of a GitHub issue. (e.g. to scrub them of file paths that may expose internal-only information).
342+
> ⚠ Warning: These files may include information from your workspace, including file paths and source code.
343+
> Both of these files are readable as plain-text, and you can modify them before attaching them as part of a GitHub issue. (e.g. to scrub them of file paths that may expose internal-only information).
344+
>
345+
> However, if you have any concerns about posting these publicly on GitHub, let us know and you can share the details privately.
346+
347+
## Reporting Editing Performance Issues
348+
349+
Perceived editing performance is frequently impacted by a number of things, and the only thing within the TypeScript team's control is the performance of the JavaScript/TypeScript language service, as well as the integration between that language service and certain editors (i.e. Visual Studio, Visual Studio Code, Visual Studio for Mac, and Sublime Text).
350+
Ensure that all 3rd-party plugins are turned off in your editor to determine whether there is an issue with TypeScript itself.
351+
352+
Editing performance issues are slightly more involved, but the same ideas apply: clone-able minimal repro codebases are ideal, and though in some cases the team will be able to sign an NDA to investigate and isolate issues.
353+
354+
Including the output from `tsc --extendedDiagnostics` is always good context, but taking a TSServer trace is the most helpful.
355+
356+
### Taking a TSServer Log
357+
358+
#### Collecting a TSServer Log in Visual Studio Code
359+
360+
1. Open up your command palette and either
361+
* open your global settings by entering `Preferences: Open User Settings`
362+
* open your local project by entering `Preferences: Open Workspace Settings`
363+
1. Set the option `"typescript.tsserver.log": "verbose",`
364+
1. Restart VS Code and reproduce the problem
365+
1. In VS Code, run the `TypeScript: Open TS Server log` command
366+
1. This should open the `tsserver.log` file.
367+
368+
⚠ Warning: A TSServer log may include information from your workspace, including file paths and source code. If you have any concerns about posting this publicly on GitHub, let us know and you can share the details privately.
369+
370+
#### Collecting a TSServer Log in Other Editors
371+
372+
You can collect a TSServer log in other editors as follows

0 commit comments

Comments
 (0)