From b9d987b08db2168948b82cb38c0c98791b9de2cd 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 1fcbd37812..5bc9ae9ef0 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -776,6 +776,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; @@ -2263,6 +2264,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 }); @@ -2278,6 +2284,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(