From acfcf40735386950e8d36f14041b321581a5b5a2 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 Aug 2014 16:09:25 -0700 Subject: [PATCH 1/2] Add uptodate checks for program object to avoid recomputation if not needed --- src/services/services.ts | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index d58fa8c529..6f727248df 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1264,21 +1264,43 @@ module ts { }; } + function sourceFileUpToDate(sourceFile: SourceFile): boolean { + return sourceFile && sourceFile.version === hostCache.getVersion(sourceFile.filename) && sourceFile.isOpen === hostCache.isOpen(sourceFile.filename); + } + + function programUpToDate(): boolean { + // If we haven't create a program yet, then it is not up-to-date + if (!program) return false; + + // If number of files in the program do not match, it is not up-to-date + var hostFilenames = hostCache.getFilenames(); + if (program.getSourceFiles().length !== hostFilenames.length) return false; + + // If any file is not up-to-date, then the whole program is not up-to-date + for (var i = 0, n = hostFilenames.length; i < n; i++) { + if (!sourceFileUpToDate(program.getSourceFile(hostFilenames[i]))) + return false; + } + + // If the compilation settings do no match, then the program is not up-to-date + return compareDataObjects(program.getCompilerOptions(), hostCache.compilationSettings()); + } + function synchronizeHostData(): void { // Reset the cache at start of every refresh hostCache = new HostCache(host); + // If the program is already up-to-date, we can reuse it + if (programUpToDate()) { + return; + } + var compilationSettings = hostCache.compilationSettings(); - // TODO: check if we need to create a new compiler to start with - // 1. files are identical - // 2. compilation settings are identical - // Now, remove any files from the compiler that are no longer in the host. var oldProgram = program; if (oldProgram) { var oldSettings = program.getCompilerOptions(); - // If the language version changed, then that affects what types of things we parse. So // we have to dump all syntax trees. // TODO: handle propagateEnumConstants @@ -1303,7 +1325,6 @@ module ts { // doesn't know about it.). Or notify the compiler about any changes (if it does // know about it.) var hostfilenames = hostCache.getFilenames(); - for (var i = 0, n = hostfilenames.length; i < n; i++) { var filename = hostfilenames[i]; @@ -1316,7 +1337,7 @@ module ts { // // If the sourceFile is the same, assume no update // - if (sourceFile.version === version && sourceFile.isOpen === isOpen) { + if (sourceFileUpToDate(sourceFile)) { continue; } From 93a48a314e4c425f30335f06129080e6f5623697 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 Aug 2014 16:56:58 -0700 Subject: [PATCH 2/2] respond to code review comments --- src/services/services.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6f727248df..849b43fa50 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1270,16 +1270,21 @@ module ts { function programUpToDate(): boolean { // If we haven't create a program yet, then it is not up-to-date - if (!program) return false; + if (!program) { + return false; + } // If number of files in the program do not match, it is not up-to-date var hostFilenames = hostCache.getFilenames(); - if (program.getSourceFiles().length !== hostFilenames.length) return false; + if (program.getSourceFiles().length !== hostFilenames.length) { + return false; + } // If any file is not up-to-date, then the whole program is not up-to-date for (var i = 0, n = hostFilenames.length; i < n; i++) { - if (!sourceFileUpToDate(program.getSourceFile(hostFilenames[i]))) + if (!sourceFileUpToDate(program.getSourceFile(hostFilenames[i]))) { return false; + } } // If the compilation settings do no match, then the program is not up-to-date