Skip to content

perf(language-server): improve snapshot reusability#196

Merged
johnsoncodehk merged 2 commits intomasterfrom
reuse-snapshot
Jun 5, 2024
Merged

perf(language-server): improve snapshot reusability#196
johnsoncodehk merged 2 commits intomasterfrom
reuse-snapshot

Conversation

@johnsoncodehk
Copy link
Member

  • Every time the file is reopened, because the SnapshotDocument instance is brand new, even if the file content hasn't changed, createVirtualCode will be rerun due to the new snapshot instance. This is resolved by using WeakRef to cache the SnapshotDocument.

  • When the file watcher is not enabled (LanguageServer#watchFiles not called), even if the file has been explicitly saved, the FS API always returns the cached result from the first request. This issue is mitigated by updating the cache in onDidSave.

  • For TS projects, the snapshot of the document during synchronization is different from the snapshot created from readFile, which causes createVirtualCode to be rerun when closing/opening the file due to switching between the document snapshot and the FS snapshot. This issue is resolved by overriding the FS snapshot cache in onDidOpen and onDidSave.

@johnsoncodehk johnsoncodehk merged commit 966b654 into master Jun 5, 2024
@johnsoncodehk johnsoncodehk deleted the reuse-snapshot branch June 5, 2024 02:08
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.

1 participant