From 9d600b9e8f47aff8c991884955c9cef60237ef9a Mon Sep 17 00:00:00 2001 From: Mahima Shanware Date: Mon, 6 Apr 2026 19:13:49 +0000 Subject: [PATCH] perf(core): cache initialized plan directories Adds caching to getPlansDir to avoid redundant synchronous disk I/O and repeated workspace context registrations. --- packages/core/src/config/config.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 7fd1a87d3e..c4931e3c13 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -781,6 +781,7 @@ export class Config implements McpContext, AgentLoopContext { private mcpServers: Record | undefined; private readonly mcpEnablementCallbacks?: McpEnablementCallbacks; private activeExtensionContext?: string; + private initializedPlanDirs = new Set(); private readonly extensionPlanDirs: Record; private userMemory: string | HierarchicalMemory; private geminiMdFileCount: number; @@ -2226,6 +2227,11 @@ export class Config implements McpContext, AgentLoopContext { getPlansDir(): string { const plansDir = this.storage.getPlansDir(this.getActiveExtensionPlanDir()); + + if (this.initializedPlanDirs.has(plansDir)) { + return plansDir; + } + try { if (!fs.existsSync(plansDir)) { fs.mkdirSync(plansDir, { recursive: true }); @@ -2241,6 +2247,7 @@ export class Config implements McpContext, AgentLoopContext { // Ignore failures in mock environments } this.workspaceContext.addDirectory(realPlansDir); + this.initializedPlanDirs.add(plansDir); } catch (e: unknown) { const errorMessage = e instanceof Error ? e.message : String(e); throw new Error(