SonarLint analysis slow and resource intensive for a single Typescript file

Hello @Tim_Feuerbach,

as for the latest question, no need to worry about the cache strategy, that’s mainly for SonarQube and SonarCloud, and the runtime API refers to SonarLint, which does not support Cache.

About the tsconfig.json files problem, it’s a non-trivial problem when dealing with projects will large amounts of tsconfig files, as the analyzer cannot know beforehand to which tsconfig.json a file belongs to.

I would advise creating a single tsconfig.json in the root of your project including all files, and only use that one in the tsconfigPath sonar property. This will override the tsconfig lookup mechanism and will force the analyzer to use the provided tsconfig file[s]. Depending on the size of the whole project it may cause memory issues (you may try increasing the node memory with the property sonar.javascript.node.maxspace increasing it to 8192 or higher), but performance should improve as it will only create one TS Program.

If a single tsconfig is not possible, I would advise creating the minimum tsconfigs needed, making each the common denominator configuration for the included files on each tsconfig file. And making sure they exclude directories that do not use their compilerOptions, to avoid having files included in more than one program. Many compilerOptions do not affect the analysis results, so it should be easier to merge tsconfigs when removing those. Any option which affects the JS output can be removed (outDir, target…). However, options affecting module detection are indeed important to properly create the program and type-check against the right dependencies (module, moduleResolution, moduleDetection, paths, lib, baseUrl…). So, if all subfolders share the same values in all of these, you may only need to use one tsconfig.

In the end, program creation for big projects takes a lot of time and the analyzer cannot avoid spending the time creating them, so any help/hint provided will help with analysis times. Creating fewer programs containing more files and properly setting files, inclusions, and exclusions will greatly help the performance. Depending on the project size, memory will then be the main issue instead.

Cheers,
Victor