From cf4da1086c6a09884b92525cf9ed8f6ff6bf8361 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Wed, 15 Jul 2026 14:57:42 -0700 Subject: [PATCH] perf(status-bar): keep the pre-ready closed-count branch allocation-free --- .../status-bar/resource-session-count-selector.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/status-bar/resource-session-count-selector.ts b/src/renderer/src/components/status-bar/resource-session-count-selector.ts index 477c9d639a5..87e83fa5748 100644 --- a/src/renderer/src/components/status-bar/resource-session-count-selector.ts +++ b/src/renderer/src/components/status-bar/resource-session-count-selector.ts @@ -73,6 +73,10 @@ function countRunningBoundPtyIds( return boundPtyIds.size - dead } +// Why: the pre-ready branch runs on every store notification during startup; +// a shared constant keeps it allocation-free. +const EMPTY_BOUND_PTY_IDS: ReadonlySet = new Set() + export function createClosedResourceSessionCountSelector( buildBindingIndex: BuildResourceSessionBindingIndex = buildResourceSessionBindingIndex ): ClosedResourceSessionCountSelector { @@ -84,7 +88,7 @@ export function createClosedResourceSessionCountSelector( let previousTerminalLayoutsByTabId: AppState['terminalLayoutsByTabId'] = {} let previousWorkspaceSessionReady = false let previousDeadPtyIds: AppState['deadPtyIds'] = {} - let boundPtyIds: ReadonlySet = new Set() + let boundPtyIds: ReadonlySet = EMPTY_BOUND_PTY_IDS let count = 0 return (state): number => { @@ -113,7 +117,7 @@ export function createClosedResourceSessionCountSelector( boundPtyIds = buildBindingIndex(state).boundPtyIds count = countRunningBoundPtyIds(boundPtyIds, state.deadPtyIds) } else if (!state.workspaceSessionReady) { - boundPtyIds = new Set() + boundPtyIds = EMPTY_BOUND_PTY_IDS count = 0 } else if (deadPtyIdsChanged) { count = countRunningBoundPtyIds(boundPtyIds, state.deadPtyIds)