-
Notifications
You must be signed in to change notification settings - Fork 676
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
Improve startup performance in VS Code #4634
Conversation
@@ -153,6 +154,9 @@ private void OnUnregisterCapability(object sender, UnregisterCapabilityEventArgs | |||
#region Workspace | |||
[JsonRpcMethod("workspace/didChangeConfiguration")] | |||
public async Task DidChangeConfiguration(JToken token, CancellationToken cancellationToken) { | |||
// Change configuration comes right after the initialization | |||
WaitForServerInitComplete(cancellationToken); |
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.
Why await server.CompleteInitialization
isn't enough?
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.
It yields, we get next request. So we end up receiving requests without having initialization complete. One option to add await CompleteInitialization to sync context and call it before any request.
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.
But DidChangeConfiguration
is called through sync context already. We have it in JsonRPC, right?
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.
It called sequentially but I do see the yield. Perhaps our sync context is incorrect.
@@ -153,6 +157,9 @@ private sealed class ReloadModulesQueueItem : IAnalyzable { | |||
} | |||
}; | |||
} | |||
|
|||
internal Task CompleteInitialization { get; private set; } = Task.CompletedTask; |
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.
This isn't safe. Awaiter may reach CompleteInitialization
before it is replaced. I'd rather go with TaskCompetionSource
:
internal async Task<InitializeResult> Initialize(InitializeParams @params, CancellationToken cancellationToken) {
ThrowIfDisposed();
if (!@params.initializationOptions.asyncStartup) {
_completeInitializationTcs.TrySetCompleted(null);
}
using (_completeInitializationTcs.RegisterForCancellation(cancellationToken)) {
await DoInitializeAsync(@params, cancellationToken);
_completeInitializationTcs.TrySetCompleted(null);
}
internal Task CompleteInitialization => _completeInitializationTcs.Task
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.
OK
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.
Although point here is NOT to await on DoInitializeAsync and just let it run. Awaiting blocks VSC startup.
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.
Actually, nothing ever called until initialized
returns. So I don't think the task can be replaced easily.
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.
So do I get it right that you want to wait for initialization to complete on the first request after initialization, rather than during initialization request itself?
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.
Yep. Those are 'open file' and 'change config' - they come after the init. Actually we need to debug why sync context does not wait for completions - or, rather, the StreamJsonRpc.
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 might need to use alternative implementation (from R/vsc) instead of sync context which actually makes sure requests do complete sequentially. See https://github.com/MikhailArkhipov/PTVS/blob/sync/Python/Product/VSCode/AnalysisVsc/LanguageServerProxy.cs
microsoft/vscode-python#1865
Basically restore async startup options we once had. This shortens wait time in VSC by ~30-40% (from 2s to 1.2s on the LS process startup. VSC it blocks between 'initialize' and 'initialized'.