-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Multifaceted approach to performantly enabling fileExists outside of the synchronize step in the emit host #25107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…the synchronize step in the emit host
src/services/services.ts
Outdated
@@ -1246,7 +1268,7 @@ namespace ts { | |||
|
|||
// hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. | |||
// It needs to be cleared to allow all collected snapshots to be released | |||
hostCache = undefined!; | |||
hostCache = hostCache.thinCopy(); // The thin copy does not cache any snapshots, just their paths, so is relatively safe to hold onto longer-term |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we should do this since in most cases we wont need it? (eg --declaration is not enabled this is not needed.. Its not needed if there is no need to create refactoring)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing it if we're fine with not having the cache available at that point; we can always come back and add it back if we discover perf is an issue here anyway.
@sheetalkamat I've removed it - we can always go add it later if we decide the perf is an issue. |
@@ -1278,11 +1278,10 @@ namespace ts { | |||
} | |||
|
|||
function getOrCreateSourceFileByPath(fileName: string, path: Path, _languageVersion: ScriptTarget, _onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined { | |||
Debug.assert(hostCache !== undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you do want to assert that hostCache !== undefined. That is getOrCreateSourceFileByPath should be called only when hostCache is not undefined.
First, in
program
, as @sheetalkamat suggested, we use the local caches if they have a result for the desired path. Since they still may not (ie, because the file isn't in the program, which is possibly the case when attempting to check paths for module specifiers), we also keep around a "thin" version of the host cache - effectively a host cache that doesn't contain any file contents, just metadata. (This way if the file is looked up for other reasons, that data is still there.) Finally, if both of those fail, we should hit disk (via the language server host).Fixes #25047
Deleting the host cache was a performance optimization so we didn't hold on to file contents for files we weren't actively using - this should retain that invariant, since we're replacing the cache with one with no content.