From af7149f604bdb2e485258fb64bed898efeea73fa Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 26 Feb 2025 07:50:01 +0100 Subject: [PATCH] chat - fix perf regression in contributions (#242021) --- .../contrib/chat/browser/chat.contribution.ts | 1 - src/vs/workbench/contrib/chat/browser/chatSetup.ts | 14 +++++++------- .../workbench/contrib/chat/browser/chatStatus.ts | 5 +++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chat.contribution.ts b/src/vs/workbench/contrib/chat/browser/chat.contribution.ts index 9a6820747a2..b4edc100f26 100644 --- a/src/vs/workbench/contrib/chat/browser/chat.contribution.ts +++ b/src/vs/workbench/contrib/chat/browser/chat.contribution.ts @@ -497,5 +497,4 @@ registerSingleton(IChatMarkdownAnchorService, ChatMarkdownAnchorService, Instant registerSingleton(ILanguageModelIgnoredFilesService, LanguageModelIgnoredFilesService, InstantiationType.Delayed); registerSingleton(IChatQuotasService, ChatQuotasService, InstantiationType.Delayed); registerSingleton(IChatEntitlementsService, ChatEntitlementsService, InstantiationType.Delayed); - registerSingleton(IPromptsService, PromptsService, InstantiationType.Delayed); diff --git a/src/vs/workbench/contrib/chat/browser/chatSetup.ts b/src/vs/workbench/contrib/chat/browser/chatSetup.ts index b60f4810dde..2a6fe9bc56b 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSetup.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSetup.ts @@ -99,8 +99,8 @@ export class ChatEntitlementsService extends Disposable implements IChatEntitlem declare _serviceBrand: undefined; - readonly context: ChatSetupContext | undefined; - readonly requests: ChatSetupRequests | undefined; + readonly context: Lazy | undefined; + readonly requests: Lazy | undefined; constructor( @IInstantiationService instantiationService: IInstantiationService, @@ -116,12 +116,12 @@ export class ChatEntitlementsService extends Disposable implements IChatEntitlem return; } - this.context = this._register(instantiationService.createInstance(ChatSetupContext)); - this.requests = this._register(instantiationService.createInstance(ChatSetupRequests, this.context)); + const context = this.context = new Lazy(() => this._register(instantiationService.createInstance(ChatSetupContext))); + this.requests = new Lazy(() => this._register(instantiationService.createInstance(ChatSetupRequests, context.value))); } async resolve(token: CancellationToken): Promise { - return this.requests?.forceResolveEntitlement(undefined, token); + return this.requests?.value.forceResolveEntitlement(undefined, token); } } @@ -143,8 +143,8 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr ) { super(); - const context = chatEntitlementsService.context; - const requests = chatEntitlementsService.requests; + const context = chatEntitlementsService.context?.value; + const requests = chatEntitlementsService.requests?.value; if (!context || !requests) { return; // disabled } diff --git a/src/vs/workbench/contrib/chat/browser/chatStatus.ts b/src/vs/workbench/contrib/chat/browser/chatStatus.ts index ac49a2a26ce..5805e5fb050 100644 --- a/src/vs/workbench/contrib/chat/browser/chatStatus.ts +++ b/src/vs/workbench/contrib/chat/browser/chatStatus.ts @@ -24,6 +24,7 @@ import { Checkbox } from '../../../../base/browser/ui/toggle/toggle.js'; import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js'; import { Command } from '../../../../editor/common/languages.js'; import { ICommandService } from '../../../../platform/commands/common/commands.js'; +import { Lazy } from '../../../../base/common/lazy.js'; export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribution { @@ -32,7 +33,7 @@ export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribu private entry: IStatusbarEntryAccessor | undefined = undefined; private readonly entryDisposables = this._register(new MutableDisposable()); - private dateFormatter = safeIntl.DateTimeFormat(language, { year: 'numeric', month: 'long', day: 'numeric' }); + private dateFormatter = new Lazy(() => safeIntl.DateTimeFormat(language, { year: 'numeric', month: 'long', day: 'numeric' })); constructor( @IStatusbarService private readonly statusbarService: IStatusbarService, @@ -147,7 +148,7 @@ export class ChatStatusBarEntry extends Disposable implements IWorkbenchContribu completionsQuotaIndicator(completionsTotal, completionsRemaining); }); - container.appendChild($('div', undefined, localize('limitQuota', "Limits will reset on {0}.", this.dateFormatter.format(quotaResetDate)))); + container.appendChild($('div', undefined, localize('limitQuota', "Limits will reset on {0}.", this.dateFormatter.value.format(quotaResetDate)))); // Settings container.appendChild($('hr'));