From bc660e7e9b502ac5ba717ecc159d78deaed5713a Mon Sep 17 00:00:00 2001 From: 777genius Date: Sun, 31 May 2026 03:46:25 +0300 Subject: [PATCH] perf(renderer): slow process-lite runtime telemetry refresh --- src/renderer/store/index.ts | 8 +++++++- test/renderer/store/teamChangeThrottle.test.ts | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/renderer/store/index.ts b/src/renderer/store/index.ts index ac63e068..043c86c0 100644 --- a/src/renderer/store/index.ts +++ b/src/renderer/store/index.ts @@ -361,6 +361,8 @@ export function initializeNotificationListeners(): () => void { const TEAM_REFRESH_THROTTLE_MS = 800; const TEAM_PRESENCE_REFRESH_THROTTLE_MS = 400; const TEAM_MEMBER_SPAWN_REFRESH_THROTTLE_MS = 500; + const TEAM_AGENT_RUNTIME_REFRESH_THROTTLE_MS = 500; + const TEAM_AGENT_RUNTIME_PROCESS_LITE_REFRESH_THROTTLE_MS = 5_000; const TEAM_LIST_REFRESH_THROTTLE_MS = 2000; const GLOBAL_TASKS_REFRESH_THROTTLE_MS = 500; const GLOBAL_TASKS_REFRESH_DURING_LAUNCH_THROTTLE_MS = 5000; @@ -512,6 +514,10 @@ export function initializeNotificationListeners(): () => void { if (teamAgentRuntimeRefreshTimers.has(timerKey)) { return; } + const throttleMs = + reason === 'event:process-lite' + ? TEAM_AGENT_RUNTIME_PROCESS_LITE_REFRESH_THROTTLE_MS + : TEAM_AGENT_RUNTIME_REFRESH_THROTTLE_MS; const timer = setTimeout(() => { teamAgentRuntimeRefreshTimers.delete(timerKey); if (options.skipIfHiddenAtExecution === true && !isTeamVisibleInAnyPane(teamName)) { @@ -533,7 +539,7 @@ export function initializeNotificationListeners(): () => void { operation: 'fetchTeamAgentRuntime', }); void useStore.getState().fetchTeamAgentRuntime(teamName); - }, TEAM_MEMBER_SPAWN_REFRESH_THROTTLE_MS); + }, throttleMs); teamAgentRuntimeRefreshTimers.set(timerKey, timer); }; const scheduleProcessLiteRuntimeRefresh = (teamName: string): void => { diff --git a/test/renderer/store/teamChangeThrottle.test.ts b/test/renderer/store/teamChangeThrottle.test.ts index 46e526d6..bd86444e 100644 --- a/test/renderer/store/teamChangeThrottle.test.ts +++ b/test/renderer/store/teamChangeThrottle.test.ts @@ -298,8 +298,7 @@ describe('team change throttling', () => { await vi.advanceTimersByTimeAsync(500); expect(fetchMemberSpawnStatusesSpy).toHaveBeenCalledTimes(1); expect(fetchMemberSpawnStatusesSpy).toHaveBeenCalledWith('my-team'); - expect(fetchTeamAgentRuntimeSpy).toHaveBeenCalledTimes(1); - expect(fetchTeamAgentRuntimeSpy).toHaveBeenCalledWith('my-team'); + expect(fetchTeamAgentRuntimeSpy).not.toHaveBeenCalled(); expect(refreshTeamDataSpy).not.toHaveBeenCalled(); expect(fetchTeamsSpy).not.toHaveBeenCalled(); @@ -312,6 +311,10 @@ describe('team change throttling', () => { expect(refreshTeamDataSpy).toHaveBeenCalledTimes(1); expect(refreshTeamDataSpy).toHaveBeenCalledWith('my-team', { withDedup: true }); + await vi.advanceTimersByTimeAsync(2_500); + expect(fetchTeamAgentRuntimeSpy).toHaveBeenCalledTimes(1); + expect(fetchTeamAgentRuntimeSpy).toHaveBeenCalledWith('my-team'); + const summary = summarizeTeamRefreshFanout('my-team'); expect(summary.rows).toEqual( expect.arrayContaining([ @@ -436,14 +439,19 @@ describe('team change throttling', () => { expect(refreshTeamDataSpy).not.toHaveBeenCalled(); await vi.advanceTimersByTimeAsync(799); expect(refreshTeamDataSpy).not.toHaveBeenCalled(); + expect(fetchMemberSpawnStatusesSpy).toHaveBeenCalledWith('my-team'); + expect(fetchTeamAgentRuntimeSpy).not.toHaveBeenCalled(); await vi.advanceTimersByTimeAsync(1); - expect(fetchMemberSpawnStatusesSpy).toHaveBeenCalledWith('my-team'); + expect(fetchMemberSpawnStatusesSpy).toHaveBeenCalledTimes(1); + expect(fetchTeamAgentRuntimeSpy).not.toHaveBeenCalled(); + + await vi.advanceTimersByTimeAsync(4_200); expect(fetchTeamAgentRuntimeSpy).toHaveBeenCalledWith('my-team'); expect(useStore.getState().selectedTeamData).toBeNull(); expect(useStore.getState().teamDataCacheByName['my-team']).toBeUndefined(); - await vi.advanceTimersByTimeAsync(19_200); + await vi.advanceTimersByTimeAsync(15_000); expect(fetchTeamsSpy).not.toHaveBeenCalled(); expect(refreshTeamDataSpy).not.toHaveBeenCalled();