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

Reorder eager extension activation #176706

Merged
merged 5 commits into from
Mar 16, 2023
Merged

Conversation

joyceerhl
Copy link
Contributor

@joyceerhl joyceerhl commented Mar 10, 2023

For #171135

In local testing (launch VS Code then open Developer: Startup Performance this exhibits a mild reduction in the time to code/didStartWorkbench. I'd like to get some additional validation in insiders for whether this makes a difference e.g. with the perf bot.

@joyceerhl joyceerhl self-assigned this Mar 10, 2023
@VSCodeTriageBot VSCodeTriageBot added this to the March 2023 milestone Mar 10, 2023
@joyceerhl joyceerhl dismissed a stale review via a077787 March 10, 2023 19:10
@joyceerhl joyceerhl requested a review from alexdima March 10, 2023 19:10
Copy link
Member

@alexdima alexdima left a comment

Choose a reason for hiding this comment

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

I like this idea very much. But here's a different way to tackle it:

  • the extension host receives startup related activation requests via AbstractExtHostExtensionService.$activateByEvent
  • from debugging this locally, all file system activation events are already received there, they're all just waiting on the readyToRunExtensions barrier
  • we could open the barrier and then wait for all activation events to finish and only then do the eager activation events (*, workspaceContains, etc).
  • this would allow to avoid having a special case for filesystems, and it would work for all kinds of startup related activation events.
  • we should test this, I only tried it locally, not on the web.

Here's a change that could be applied on main to get what I describe:

diff --git a/src/vs/workbench/api/common/extHostExtensionActivator.ts b/src/vs/workbench/api/common/extHostExtensionActivator.ts
index 47f20ca08dd..26c8795aaa6 100644
--- a/src/vs/workbench/api/common/extHostExtensionActivator.ts
+++ b/src/vs/workbench/api/common/extHostExtensionActivator.ts
@@ -193,6 +193,14 @@ export class ExtensionsActivator implements IDisposable {
 		}
 	}
 
+	public async waitForActivatingExtensions(): Promise<void> {
+		const res: Promise<boolean>[] = [];
+		for (const [_, op] of this._operations) {
+			res.push(op.wait());
+		}
+		await Promise.all(res);
+	}
+
 	public isActivated(extensionId: ExtensionIdentifier): boolean {
 		const op = this._operations.get(extensionId);
 		return Boolean(op && op.value);
diff --git a/src/vs/workbench/api/common/extHostExtensionService.ts b/src/vs/workbench/api/common/extHostExtensionService.ts
index 0b0dba8355b..afe2939e5b8 100644
--- a/src/vs/workbench/api/common/extHostExtensionService.ts
+++ b/src/vs/workbench/api/common/extHostExtensionService.ts
@@ -756,6 +756,10 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
 
 		return this._readyToStartExtensionHost.wait()
 			.then(() => this._readyToRunExtensions.open())
+			.then(() => {
+				// wait for all activation events that came in during workbench startup, but at maximum 1s
+				return Promise.race([this._activator.waitForActivatingExtensions(), timeout(1000)]);
+			})
 			.then(() => this._handleEagerExtensions())
 			.then(() => {
 				this._eagerExtensionsActivated.open();

@joyceerhl joyceerhl marked this pull request as draft March 16, 2023 05:43
@joyceerhl
Copy link
Contributor Author

@alexdima I just tried this out https://insiders.vscode.dev/github/microsoft/vscode?vscode-version=9402aef94bbb84354fe22b3455a13750be79e3f5 and it seems to work well in web and remote. Thank you for the pointer!

@joyceerhl joyceerhl marked this pull request as ready for review March 16, 2023 21:39
@joyceerhl joyceerhl requested a review from alexdima March 16, 2023 21:41
@joyceerhl joyceerhl merged commit e440a9b into main Mar 16, 2023
@joyceerhl joyceerhl deleted the dev/joyceerhl/small-barnacle branch March 16, 2023 23:21
@github-actions github-actions bot locked and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants