diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 772bd71bcfc..949eff078cb 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -398,7 +398,7 @@ export class CodeApplication extends Disposable { const windows = appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, electronIpcServer, sharedProcessClient)); // Post Open Windows Tasks - this.afterWindowOpen(); + appInstantiationService.invokeFunction(this.afterWindowOpen.bind(this)); // Tracing: Stop tracing after windows are ready if enabled if (this.environmentService.args.trace) { @@ -714,13 +714,18 @@ export class CodeApplication extends Disposable { return { fileUri: URI.file(path) }; } - private afterWindowOpen(): void { - + private afterWindowOpen(accessor: ServicesAccessor): void { // Signal phase: after window open this.lifecycleMainService.phase = LifecycleMainPhase.AfterWindowOpen; // Remote Authorities this.handleRemoteAuthorities(); + + // Initialize update service + const updateService = accessor.get(IUpdateService); + if (updateService instanceof Win32UpdateService || updateService instanceof LinuxUpdateService || updateService instanceof DarwinUpdateService) { + updateService.initialize(); + } } private handleRemoteAuthorities(): void { diff --git a/src/vs/platform/update/electron-main/abstractUpdateService.ts b/src/vs/platform/update/electron-main/abstractUpdateService.ts index d8bf464fed9..380f553f5d8 100644 --- a/src/vs/platform/update/electron-main/abstractUpdateService.ts +++ b/src/vs/platform/update/electron-main/abstractUpdateService.ts @@ -26,7 +26,7 @@ export abstract class AbstractUpdateService implements IUpdateService { _serviceBrand: undefined; - protected readonly url: string | undefined; + protected url: string | undefined; private _state: State = State.Uninitialized; @@ -49,7 +49,14 @@ export abstract class AbstractUpdateService implements IUpdateService { @IEnvironmentService private readonly environmentService: IEnvironmentService, @IRequestService protected requestService: IRequestService, @ILogService protected logService: ILogService, - ) { + ) { } + + /** + * This must be called before any other call. This is a performance + * optimization, to avoid using extra CPU cycles before first window open. + * https://github.com/microsoft/vscode/issues/89784 + */ + initialize(): void { if (!this.environmentService.isBuilt) { return; // updates are never enabled when running out of sources } @@ -173,6 +180,7 @@ export abstract class AbstractUpdateService implements IUpdateService { if (!this.url) { return Promise.resolve(undefined); } + return this.requestService.request({ url: this.url }, CancellationToken.None).then(context => { // The update server replies with 204 (No Content) when no // update is available - that's all we want to know. diff --git a/src/vs/platform/update/electron-main/updateService.darwin.ts b/src/vs/platform/update/electron-main/updateService.darwin.ts index d25c577b66e..c3f9210c24e 100644 --- a/src/vs/platform/update/electron-main/updateService.darwin.ts +++ b/src/vs/platform/update/electron-main/updateService.darwin.ts @@ -36,6 +36,10 @@ export class DarwinUpdateService extends AbstractUpdateService { @ILogService logService: ILogService ) { super(lifecycleMainService, configurationService, environmentService, requestService, logService); + } + + initialize(): void { + super.initialize(); this.onRawError(this.onError, this, this.disposables); this.onRawUpdateAvailable(this.onUpdateAvailable, this, this.disposables); this.onRawUpdateDownloaded(this.onUpdateDownloaded, this, this.disposables); diff --git a/src/vs/platform/update/electron-main/updateService.win32.ts b/src/vs/platform/update/electron-main/updateService.win32.ts index 8f87787b9e7..7c7948d79b5 100644 --- a/src/vs/platform/update/electron-main/updateService.win32.ts +++ b/src/vs/platform/update/electron-main/updateService.win32.ts @@ -69,6 +69,10 @@ export class Win32UpdateService extends AbstractUpdateService { @IFileService private readonly fileService: IFileService ) { super(lifecycleMainService, configurationService, environmentService, requestService, logService); + } + + initialize(): void { + super.initialize(); if (getUpdateType() === UpdateType.Setup) { /* __GDPR__ @@ -81,7 +85,7 @@ export class Win32UpdateService extends AbstractUpdateService { "target" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } } */ - telemetryService.publicLog('update:win32SetupTarget', { target: product.target }); + this.telemetryService.publicLog('update:win32SetupTarget', { target: product.target }); } }