From d69f055597e21fefa46f6c112b2e3f784ff91c54 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 17 Feb 2026 07:53:34 +0000 Subject: [PATCH] Add CI toggle to skip benchmark thread sweep Co-authored-by: Julius Marminge --- .github/workflows/ci.yml | 3 ++ apps/desktop/src/desktopPerfAutomation.ts | 48 +++++++++++++---------- apps/desktop/src/perfConfig.test.ts | 23 +++++++++++ apps/desktop/src/perfConfig.ts | 11 ++++++ 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a97e15c099..1fab5eed48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,6 +83,7 @@ jobs: # Terminal PTY scripting is flaky in CI VMs; renderer perf checks remain enforced. T3CODE_DESKTOP_PERF_RUN_TERMINAL: "0" T3CODE_DESKTOP_PERF_RUN_OPTIONAL_RENDERER: "0" + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: "0" T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "0" T3CODE_ELECTRON_STARTUP_TIMEOUT_MS: "180000" run: xvfb-run -a bun run test:desktop-perf @@ -95,6 +96,7 @@ jobs: T3CODE_PERF_MAX_LONG_DISPATCH_COUNT: "5" T3CODE_DESKTOP_PERF_RUN_TERMINAL: "0" T3CODE_DESKTOP_PERF_RUN_OPTIONAL_RENDERER: "0" + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: "0" T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "0" T3CODE_ELECTRON_STARTUP_TIMEOUT_MS: "180000" run: xvfb-run -a bun run test:desktop-perf @@ -108,6 +110,7 @@ jobs: T3CODE_PERF_MAX_LONG_DISPATCH_COUNT: "5" T3CODE_DESKTOP_PERF_RUN_TERMINAL: "0" T3CODE_DESKTOP_PERF_RUN_OPTIONAL_RENDERER: "0" + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: "0" T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "0" T3CODE_ELECTRON_STARTUP_TIMEOUT_MS: "180000" run: xvfb-run -a bun run test:desktop-perf:post diff --git a/apps/desktop/src/desktopPerfAutomation.ts b/apps/desktop/src/desktopPerfAutomation.ts index 475f101e0d..e27f1d90ee 100644 --- a/apps/desktop/src/desktopPerfAutomation.ts +++ b/apps/desktop/src/desktopPerfAutomation.ts @@ -6,6 +6,7 @@ import path from "node:path"; import { BrowserWindow, contentTracing, type WebContents } from "electron"; import { resolveBenchmarkFollowUpPassCount, + shouldRunBenchmarkThreadSweep, shouldRunOptionalRendererPerfInteractions, shouldRunTerminalPerfInteractions, } from "./perfConfig"; @@ -27,6 +28,10 @@ const BENCHMARK_FOLLOW_UP_PASS_COUNT = resolveBenchmarkFollowUpPassCount({ process.env.T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES, CI: process.env.CI, }); +const RUN_BENCHMARK_THREAD_SWEEP = shouldRunBenchmarkThreadSweep({ + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: process.env.T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP, + CI: process.env.CI, +}); function delay(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); @@ -575,13 +580,14 @@ async function runRendererPerfInteractions( return Number((sorted[middle] ?? 0).toFixed(2)); }; + const runBenchmarkThreadSweep = ${RUN_BENCHMARK_THREAD_SWEEP}; const preferredThreadIds = ${JSON.stringify(benchmarkThreadIds)}.filter( (value) => typeof value === "string" && value.length > 0, ); - const benchmarkThreadIds = preferredThreadIds.filter((threadId) => - renderedThreadIds.includes(threadId), - ); - if (benchmarkThreadIds.length === 0) { + const benchmarkThreadIds = runBenchmarkThreadSweep + ? preferredThreadIds.filter((threadId) => renderedThreadIds.includes(threadId)) + : []; + if (runBenchmarkThreadSweep && benchmarkThreadIds.length === 0) { benchmarkThreadIds.push(...renderedThreadIds.slice(0, ${BENCHMARK_THREAD_COUNT})); } @@ -599,25 +605,27 @@ async function runRendererPerfInteractions( }; const firstPassByThreadId = new Map(); - for (const threadId of benchmarkThreadIds) { - await ensureThreadSwitchTarget(threadId); - firstPassByThreadId.set(threadId, await measureThreadRender(threadId)); - } - const followUpSamplesByThreadId = new Map(); - for (const threadId of benchmarkThreadIds) { - followUpSamplesByThreadId.set(threadId, []); - } - const followUpPassCount = ${BENCHMARK_FOLLOW_UP_PASS_COUNT}; - for (let passIndex = 0; passIndex < followUpPassCount; passIndex += 1) { + if (runBenchmarkThreadSweep) { for (const threadId of benchmarkThreadIds) { await ensureThreadSwitchTarget(threadId); - const sample = await measureThreadRender(threadId); - const samples = followUpSamplesByThreadId.get(threadId); - if (Array.isArray(samples)) { - samples.push(sample.renderMs); - } else { - followUpSamplesByThreadId.set(threadId, [sample.renderMs]); + firstPassByThreadId.set(threadId, await measureThreadRender(threadId)); + } + + for (const threadId of benchmarkThreadIds) { + followUpSamplesByThreadId.set(threadId, []); + } + const followUpPassCount = ${BENCHMARK_FOLLOW_UP_PASS_COUNT}; + for (let passIndex = 0; passIndex < followUpPassCount; passIndex += 1) { + for (const threadId of benchmarkThreadIds) { + await ensureThreadSwitchTarget(threadId); + const sample = await measureThreadRender(threadId); + const samples = followUpSamplesByThreadId.get(threadId); + if (Array.isArray(samples)) { + samples.push(sample.renderMs); + } else { + followUpSamplesByThreadId.set(threadId, [sample.renderMs]); + } } } } diff --git a/apps/desktop/src/perfConfig.test.ts b/apps/desktop/src/perfConfig.test.ts index 3a9ab519de..926ceb6967 100644 --- a/apps/desktop/src/perfConfig.test.ts +++ b/apps/desktop/src/perfConfig.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import { resolveBenchmarkFollowUpPassCount, + shouldRunBenchmarkThreadSweep, shouldRunOptionalRendererPerfInteractions, shouldRunTerminalPerfInteractions, } from "./perfConfig"; @@ -207,3 +208,25 @@ describe("shouldRunOptionalRendererPerfInteractions", () => { ).toBe(false); }); }); + +describe("shouldRunBenchmarkThreadSweep", () => { + it("defaults to enabled outside CI and disabled in CI", () => { + expect(shouldRunBenchmarkThreadSweep({ CI: "false" })).toBe(true); + expect(shouldRunBenchmarkThreadSweep({ CI: "true" })).toBe(false); + }); + + it("supports explicit env overrides", () => { + expect( + shouldRunBenchmarkThreadSweep({ + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: "1", + CI: "true", + }), + ).toBe(true); + expect( + shouldRunBenchmarkThreadSweep({ + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP: "off", + CI: "false", + }), + ).toBe(false); + }); +}); diff --git a/apps/desktop/src/perfConfig.ts b/apps/desktop/src/perfConfig.ts index c904122057..c1610123aa 100644 --- a/apps/desktop/src/perfConfig.ts +++ b/apps/desktop/src/perfConfig.ts @@ -13,6 +13,11 @@ type PerfBenchmarkEnv = { CI?: string | undefined; }; +type BenchmarkSweepToggleEnv = { + T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP?: string | undefined; + CI?: string | undefined; +}; + const TRUE_VALUES = new Set(["1", "true", "yes", "on"]); const FALSE_VALUES = new Set(["0", "false", "no", "off"]); const MAX_BENCHMARK_FOLLOW_UP_PASSES = 5; @@ -52,6 +57,12 @@ export function shouldRunOptionalRendererPerfInteractions(env: OptionalRendererT return !isCiEnvironment(env.CI); } +export function shouldRunBenchmarkThreadSweep(env: BenchmarkSweepToggleEnv): boolean { + const toggleOverride = parseBooleanLike(env.T3CODE_DESKTOP_PERF_RUN_BENCHMARK_SWEEP); + if (toggleOverride !== null) return toggleOverride; + return !isCiEnvironment(env.CI); +} + export function resolveBenchmarkFollowUpPassCount(env: PerfBenchmarkEnv): number { const raw = env.T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES?.trim(); if (raw && /^\d+$/.test(raw)) {