TypeScript: IntelliSense slow down with large json file
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.65.2
- OS Version: Ubuntu 20.04.4 LTS
IntelliSense slow down when I set value for compilerOptions->jsx option in tsconfig.json file. Without this option (after restart vscode) I get autocomplete suggestion less then 1 second, with compilerOptions->jsx I get suggestion after 3-4 seconds. CPU i5 8 cores, available RAM more than 10GB.
When initializing js/ts language features in progress IntelliSense work fast
Tried in 1.66.0-insider the result is the same
{
"compilerOptions": {
...
"jsx": "react",
...
},
"exclude": [...]
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 19 (7 by maintainers)
Update on this bug: I’ve looked into making type checking array literals faster, but it doesn’t look like this would be enough to solve the intellisense slowdown for the examples listed here. Instead, what I suggest as a fix is the following: If you’re importing a large JSON (array) module with
resolveJsonModuleset, and you’re experiencing slow intellisense in the file(s) that imports this JSON (e.g. slow completions, slow updates to errors/red squiggles, etc), you can set our new flag"allowArbitraryExtensions": trueon your tsconfig’scompilerOptions, and write a.d.json.tsfile with the type of your JSON module.Example:
index.ts:myJson.json:myJson.d.json.ts:Then, when importing the JSON, TS will get the types from your
.d.json.tsfile instead of type checking the JSON every time your file changes in the editor, making it way faster.The
allowArbitraryExtensionsflag is currently only present on the nightly versions, but it will be officially available starting at the 5.0 beta version that we’ll release in the next couple weeks.I’ve been investigating this issue, and at least for the example large jsons provided here (by @steve-ross and the json files in @ryancwalsh’s
paintcolornerd), it seems what is happening is that we’re taking too long to type check the very large array in the json file, because in those cases the kind of type checking/inference we do is quadratic on the size of the array literal. This affects intellisense because, in general, when you open or change something in your file that imports the large json, we have to type check it again, and it takes a while. So there’s a general slowdown on things like completions, updating errors/red squiggles, quickinfo, etc, that rely on having your file type checked.I’m now going to think about ways in which we could improve this.
Curious discovery
Out of curiosity, I decided to try using require instead of import, and to my surprise, it worked. However, when I hovered over the require, I received a warning that said “‘require’ call may be converted to an import.” Despite this, I noticed that if I didn’t click on “Quick Fix” to convert the require to an import, IntelliSense no longer experienced delays.
This finding suggests that there may be a difference in IntelliSense performance when using require instead of import in certain situations. It would be interesting to further investigate to understand why this behavior occurs and if there is any technical explanation behind it.
I finally found this issue after days of this problem. I’d been disabling all of my VSC extensions trying to figure out why Intellisense got so slow for a project of mine.
I finally narrowed it down to this one line in a file:
import megaColors from '../data/colornerd.json';The JSON is 3 MB. Having that one line makes Intellisense unusably slow for the whole project.
steve-ross in the future can you please make sure to open a new issue when reporting problems. I just assumed you were the OP but I think you’re talking about a different problem than what @sublite originally reported
@sublite If you’re seeing the original problem, please share a project that demonstrates the issue