Skip to content

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

Merged
merged 5 commits into from
Jun 22, 2018

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Jun 20, 2018

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.

@weswigham weswigham requested review from sheetalkamat and a user June 20, 2018 20:51
@@ -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
Copy link
Member

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)

Copy link
Member Author

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.

@weswigham
Copy link
Member Author

@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);
Copy link
Member

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.

@weswigham weswigham merged commit bd97e12 into microsoft:master Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants