Skip to content
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

Closed
wants to merge 7 commits into from
Closed

Improve startup performance in VS Code #4634

wants to merge 7 commits into from

Conversation

MikhailArkhipov
Copy link

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'.

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

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?

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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;
Copy link
Contributor

@AlexanderSher AlexanderSher Aug 14, 2018

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Author

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.

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Author

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

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