TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

program recreated on every services call (programUpToDate always returns false)

Open jeffreymorlan opened this issue 11 years ago • 3 comments

From programUpToDate in services/services.ts:

// If number of files in the program do not match, it is not up-to-date
let rootFileNames = hostCache.getRootFileNames();
if (program.getSourceFiles().length !== rootFileNames.length) {
    return false;
}

program.getSourceFiles() is generally longer than rootFileNames, because it includes non-root files (the default lib lib.d.ts, plus any files included by import or <reference>)

As a result of this, program is re-created on every synchronizeHostData call, resulting in a lot of unnecessary work being done.

jeffreymorlan avatar Sep 28 '15 23:09 jeffreymorlan

Which version are you using?

with 1.6, createProgram takes an old program as an option allowing for reusing almost all of the program structure. the time spent in "refreshing" a program if nothing changed should be in the order of 10 ms. if you are not seeing that, then there is something more going on.

mhegazy avatar Sep 28 '15 23:09 mhegazy

Version 1.6. createProgram doesn't take a long time itself, but it does mean that calling getSemanticDiagnostics on all source files in a large project takes significantly longer than it should (over twice as long). Type checking one file requires doing some of the work to type check other files, and that work gets thrown away if the program is recreated for each file.

As a workaround I'm implementing getProjectVersion in the LanguageServiceHost, but other editors probably don't do that (tsserver doesn't at least)

jeffreymorlan avatar Sep 28 '15 23:09 jeffreymorlan

that is correct. you have two options, you can implement as you noted getProjectVersion, or make sure you do the resolution separably and make sure to pass all files to the language service, so that the program will always be used (i.e. rootfiles === oldProgram.sourceFiles()).

For tsserver, it does not query for all files for errors, it only does for open files, which limits the number of requests.

the value here is it simplifies the host implementation, and the host does not even need to know about what a project is.

mhegazy avatar Sep 29 '15 00:09 mhegazy