Файли
openidea/perf/scenarios.ts
T
audichuang 0a146e4ac9 perf(run): mark the console scenario's sequential awaits as intentional (#5707)
The consoleLongLines perf scenario and the sample console stream await one wheel step, scroll position or output batch per frame on purpose; mark those awaits so no-await-in-loop no longer fails lint on main.

Co-authored-by: audichuang <[email protected]>
2026-11-25 07:21:42 +08:00

1164 рядки
49 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Interaction scenarios. Each returns flat metrics (lower is better); budgets in
* `budgets.json` are keyed `<scenario>.<metric>`.
*/
import { Harness, type Metrics, type Scenario } from "./lib/harness.ts";
import { frameSummary, keySummary, latencySummary, totalBlockingTime } from "./lib/stats.ts";
import { startTuiRowObserver, stopTuiRowObserver } from "./lib/tuiRows.ts";
const ROOT = "/dev/acme-api";
const SAMPLE = `${ROOT}/src/main/kotlin/com/acme/orders/service/OrderService.kt`;
/** ~`lines` lines of TypeScript with a unique first line. */
function tsSource(lines: number, tag: string): string {
const out = [`// ${tag}`, `import { Injectable } from "./di";`, ""];
for (let i = 0; out.length < lines; i++) {
out.push(
`/** Repository for entity ${i}. */`,
`export class Repository${i}<T extends { id: number }> {`,
` private readonly items = new Map<number, T>();`,
` constructor(private readonly name = "repo-${i}") {}`,
` find(id: number): T | undefined {`,
` return this.items.get(id) ?? (id > ${i} ? undefined : this.items.get(${i}));`,
` }`,
` save(item: T): void {`,
` if (item.id < 0) throw new Error(\`invalid id \${item.id} in \${this.name}\`);`,
` this.items.set(item.id, item);`,
` }`,
`}`,
``,
);
}
return out.join("\n");
}
/** ~`lines` lines of an Angular template: bindings, interpolations and control-flow blocks. */
function angularTemplate(lines: number, tag: string): string {
const out = [`<!-- ${tag} -->`];
for (let i = 0; out.length < lines; i++) {
out.push(
`<section class="card" [class.active]="selected() === ${i}">`,
` <h2 (click)="select(${i})">{{ title${i}() | titlecase }}</h2>`,
` @if (items${i}().length) {`,
` <ul>`,
` @for (item of items${i}(); track item.id; let last = $last) {`,
` <li [title]="item.label" (keydown.enter)="open(item)">{{ item.name }} &amp; {{ item.count }}</li>`,
` } @empty {`,
` <li>None</li>`,
` }`,
` </ul>`,
` } @else {`,
` <p>Loading</p>`,
` }`,
`</section>`,
`@let total${i} = items${i}().length + ${i};`,
``,
);
}
return out.join("\n");
}
const TYPED = 'val total = orders.sumOf { it.amount * (1 + rate) }\nif (total > limit) log("over limit")\n';
/** Typing at a brisk pace (~12 keys/s) in the small Kotlin sample. */
const typing: Scenario = {
id: "typing",
title: "Type into a small Kotlin file",
async run(h) {
await h.openFile(SAMPLE);
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
await h.page.keyboard.press("End");
await h.page.keyboard.press("Enter");
return typeAndMeasure(h, TYPED, 80);
},
};
/**
* The same typing in the middle of a ~20k-line (≈ 700 KB) TypeScript file, once
* the background parse after opening has settled.
*/
const typingLarge: Scenario = {
id: "typingLarge",
title: "Type into a 20k-line TypeScript file",
async run(h) {
const openMs = await h.openFile(`${ROOT}/src/big/Repositories.ts`, tsSource(20_000, "big"));
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
await h.parserIdle();
await h.page.keyboard.press("End");
await h.page.keyboard.press("Enter");
return { openMs, ...(await typeAndMeasure(h, "const total = items.reduce((a, b) => a + b.id, 0);\n", 80)) };
},
};
/**
* The same typing in the middle of a ~12k-line Angular template (an
* `angular.json` above it): its text, attributes and blocks are nested parses.
*/
const typingAngular: Scenario = {
id: "typingAngular",
title: "Type into a 12k-line Angular template",
async run(h) {
await h.seed(`${ROOT}/web/angular.json`, "{}");
const openMs = await h.openFile(`${ROOT}/web/src/app/big.component.html`, angularTemplate(12_000, "big"));
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
await h.parserIdle();
await h.page.keyboard.press("End");
await h.page.keyboard.press("Enter");
return { openMs, ...(await typeAndMeasure(h, "@if (open()) { {{ total + 1 }} items }\n", 80)) };
},
};
/**
* Code completion with a language server's 2,000 items: the first letter opens
* the popup (after CodeMirror's 100 ms typing delay), each further letter
* narrows it, arrows move the selection.
*/
const completion: Scenario = {
id: "completion",
title: "Code completion over 2,000 items",
async run(h) {
await h.page.evaluate(() =>
(window as never as { __openideaPerf: { fakeCompletion(n: number): void } }).__openideaPerf.fakeCompletion(2_000),
);
try {
await h.openFile(`${ROOT}/src/completion/Orders.ts`, tsSource(2_000, "completion"));
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
await h.parserIdle();
await h.page.keyboard.press("End");
await h.page.keyboard.press("Enter");
const refresh = await h.refreshMs();
const openMs = await h.measure(() => h.page.keyboard.press("g"), ".cm-tooltip-autocomplete li", "Result<Order>");
const t0 = await h.now();
const before = await h.counters();
const narrow = await h.typeMeasured("etOrd", 150);
const work = Harness.delta(before, await h.counters());
const arrows = await h.completionArrowsMeasured(20, 60);
await h.page.keyboard.press("Escape");
return {
openMs,
...keySummary(narrow, refresh, "narrow"),
narrowMainThreadMsPerKey: work.taskMs / 5,
...keySummary(arrows, refresh, "arrow"),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
};
} finally {
await h.page.evaluate(() =>
(window as never as { __openideaPerf: { fakeCompletion(n: number): void } }).__openideaPerf.fakeCompletion(0),
);
}
},
};
/**
* A process printing 50,000 log lines (stack frames among them) at 200 lines a
* frame (~4 s) into the Run console, while the user types in an editor: the
* console must keep up and the editor must stay responsive.
*/
const consoleOutput: Scenario = {
id: "consoleOutput",
title: "Type while the Run console streams 50k lines",
async run(h) {
await h.openFile(SAMPLE);
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
await h.page.keyboard.press("End");
await h.page.keyboard.press("Enter");
const refresh = await h.refreshMs();
const t0 = await h.now();
await h.inPage((p) => p.startFrames());
const streamMs = h.page.evaluate(async () => {
const w = window as never as { __openideaPerf: { runAction(id: string, arg?: unknown): Promise<boolean> } };
const started = performance.now();
await w.__openideaPerf.runAction("run.sampleOutput", { lines: 50_000, perFrame: 200 });
return performance.now() - started;
});
// The console takes focus with it; type back in the editor while it streams.
await h.page.waitForTimeout(100);
await h.setCursor((await h.editorState())?.head ?? 0);
const keys = await h.typeMeasured(TYPED.slice(0, 40), 70);
const total = await streamMs;
const frames = await h.inPage((p) => p.stopFrames());
await h.inPage((p) => p.waitShown("body", "processed order #49998", 5_000));
return {
// 250 frames of output at the display rate is the floor.
streamMs: total,
...frameSummary(frames, refresh),
...keySummary(keys, refresh, "key"),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
};
},
};
/**
* Run console with 10 KiB long lines and high-rate output without newlines
* (with Find open while streaming). `OPENIDEA_PERF_SCALE` scales counts across
* 1× / 10× / 100× (default 10×).
*
* Why `consoleOutput` above missed the stall: its `SAMPLE_LINES`
* (`src/features/run/store.ts`) are short (~70–150 char), newline-terminated
* lines with Find closed, so it never runs link detection on multi-KiB lines.
* The `x` fill is the worst case for path matching: one long run of path characters.
*/
const consoleLongLines: Scenario = {
id: "consoleLongLines",
title: "Stream 10 KiB long lines and no-newline output in the Run console",
async run(h) {
const scale = Math.max(1, Number(process.env.OPENIDEA_PERF_SCALE ?? "10"));
const longCount = Math.round(100 * scale);
const longPerFrame = Math.max(2, Math.ceil(longCount / 50));
const noLfCount = Math.round(1_000 * scale);
const noLfPerFrame = Math.max(20, Math.ceil(noLfCount / 60));
type ConsolePerfWindow = {
__openideaPerf: {
openConsoleSession(mode: "long" | "no-lf"): Promise<string>;
streamConsoleOutput(o: {
mode: "long" | "no-lf";
count: number;
perFrame: number;
sessionId?: string;
}): Promise<{
lines: number;
dropped: number;
}>;
};
};
await h.openFile(SAMPLE);
const refresh = await h.refreshMs();
// Phase 1: 10 KiB unique long lines streaming (each splits at 8,000 + 2,239 chars in ConsoleModel).
const longSessionId = await h.page.evaluate(() =>
(window as never as ConsolePerfWindow).__openideaPerf.openConsoleSession("long"),
);
const longLog = h.page.locator('section[aria-label="Run"] [role="log"][aria-label="Sample long output"]').first();
await longLog.waitFor({ timeout: 10_000 });
const tLong = await h.now();
await h.inPage((p) => p.startFrames());
const longStream = h.page.evaluate(
async ({ sessionId, count, perFrame }) => {
const started = performance.now();
await (window as never as ConsolePerfWindow).__openideaPerf.streamConsoleOutput({
mode: "long",
sessionId,
count,
perFrame,
});
return performance.now() - started;
},
{ sessionId: longSessionId, count: longCount, perFrame: longPerFrame },
);
const longBox = await longLog.boundingBox();
if (longBox) {
await h.page.mouse.move(longBox.x + longBox.width / 2, longBox.y + longBox.height / 2);
for (let i = 0; i < 6; i++) {
// oxlint-disable-next-line no-await-in-loop -- wheel steps scroll the log one after another while it streams
await h.page.mouse.wheel(0, -180);
// oxlint-disable-next-line no-await-in-loop -- spaces the wheel steps out
await h.page.waitForTimeout(40);
}
}
const longStreamMs = await longStream;
const longFrames = await h.inPage((p) => p.stopFrames());
const longSummary = frameSummary(longFrames, refresh);
const longTbtMs = totalBlockingTime(await h.longTasksSince(tLong));
const longDomNodes = await h.page.evaluate(() => document.querySelectorAll("*").length);
// Phase 2: mount the no-newline session and open Find ("t") before measurement or streaming starts,
// so the entire stream is measured, then scroll horizontally across the 8,000-char rows.
const noLfSessionId = await h.page.evaluate(() =>
(window as never as ConsolePerfWindow).__openideaPerf.openConsoleSession("no-lf"),
);
const noLfLog = h.page.locator('section[aria-label="Run"] [role="log"][aria-label="Sample no-lf output"]').first();
await noLfLog.waitFor({ timeout: 10_000 });
const findBtn = h.page.locator('section[aria-label="Run"] button[aria-label="Find…"]').first();
await findBtn.waitFor({ timeout: 10_000 });
await findBtn.click();
const findInput = h.page.locator("[data-console-find] input").first();
await findInput.waitFor({ timeout: 10_000 });
await findInput.fill("t");
const tNoLf = await h.now();
await h.inPage((p) => p.startFrames());
const noLfStreamMs = await h.page.evaluate(
async ({ sessionId, count, perFrame }) => {
const started = performance.now();
await (window as never as ConsolePerfWindow).__openideaPerf.streamConsoleOutput({
mode: "no-lf",
sessionId,
count,
perFrame,
});
return performance.now() - started;
},
{ sessionId: noLfSessionId, count: noLfCount, perFrame: noLfPerFrame },
);
// Sweep scrollLeft across the wide 8,000-char rows with Find open.
await noLfLog.evaluate(async (el) => {
const maxLeft = Math.max(0, el.scrollWidth - el.clientWidth);
const steps = 12;
for (let i = 1; i <= steps; i++) {
el.scrollLeft = Math.round((maxLeft * i) / steps);
// oxlint-disable-next-line no-await-in-loop -- one horizontal scroll position per frame
await new Promise(requestAnimationFrame);
}
el.scrollLeft = 0;
await new Promise(requestAnimationFrame);
});
const noLfFrames = await h.inPage((p) => p.stopFrames());
const noLfSummary = frameSummary(noLfFrames, refresh);
const noLfTbtMs = totalBlockingTime(await h.longTasksSince(tNoLf));
const noLfDomNodes = await h.page.evaluate(() => document.querySelectorAll("*").length);
return {
longStreamMs,
longFrameP95Ms: longSummary.frameP95Ms,
longFrameMaxMs: longSummary.frameMaxMs,
longDroppedFramesPct: longSummary.droppedFramesPct,
longTbtMs,
longDomNodes,
noLfStreamMs,
noLfFrameP95Ms: noLfSummary.frameP95Ms,
noLfFrameMaxMs: noLfSummary.frameMaxMs,
noLfDroppedFramesPct: noLfSummary.droppedFramesPct,
noLfTbtMs,
noLfDomNodes,
};
},
};
/**
* A full-screen agent TUI (Claude Code, Grok) repainting the terminal 10 times a second
* for 6 s — every row rewritten, only the spinner row changed — while the user types in
* an editor. Guards the terminal's unchanged-row skip: without it every frame restyles
* and lays out the whole screen.
*/
const TUI_FRAMES = 60;
const terminalTui: Scenario = {
id: "terminalTui",
title: "Type while a full-screen TUI repaints the terminal",
async run(h) {
await h.openFile(SAMPLE);
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 2));
// Open the terminal and let it settle before measuring.
const opened = await h.page.evaluate(() =>
(
window as never as { __openideaPerf: { runAction(id: string, arg?: unknown): Promise<boolean> } }
).__openideaPerf.runAction("terminal.sampleTui", { frames: 1, fps: 10 }),
);
if (!opened) throw new Error("terminal.sampleTui is unavailable");
await h.page.waitForTimeout(300);
await h.setCursor((await h.editorState())?.head ?? 0);
const refresh = await h.refreshMs();
const t0 = await h.now();
const before = await h.counters();
await h.page.evaluate(startTuiRowObserver);
await h.inPage((p) => p.startFrames());
const stream = h.page.evaluate(
(frames) =>
(
window as never as { __openideaPerf: { runAction(id: string, arg?: unknown): Promise<boolean> } }
).__openideaPerf.runAction("terminal.sampleTui", { frames, fps: 10 }),
TUI_FRAMES,
);
let keys: number[];
let rebuilt: number;
try {
await h.page.waitForTimeout(200);
await h.setCursor((await h.editorState())?.head ?? 0);
keys = await h.typeMeasured(TYPED.slice(0, 40), 70);
if (!(await stream)) throw new Error("terminal.sampleTui is unavailable");
} finally {
rebuilt = await h.page.evaluate(stopTuiRowObserver);
}
const frames = await h.inPage((p) => p.stopFrames());
const work = Harness.delta(before, await h.counters());
return {
// ~1 with unchanged rows left in place (only the spinner row changes), the screen height without.
rowsRebuiltPerTuiFrame: rebuilt / TUI_FRAMES,
styleLayoutMsPerTuiFrame: work.styleLayoutMs / TUI_FRAMES,
scriptMsPerTuiFrame: work.scriptMs / TUI_FRAMES,
...frameSummary(frames, refresh),
...keySummary(keys, refresh, "key"),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
};
},
};
/** Held key: auto-repeat at ~30 Hz must never fall behind. */
const keyRepeat: Scenario = {
id: "keyRepeat",
title: "Auto-repeat a key in a 20k-line file",
async run(h) {
await h.openFile(`${ROOT}/src/big/Repeat.ts`, tsSource(20_000, "repeat"));
const st = await h.editorState();
await h.setCursor(Math.floor((st?.length ?? 0) / 3));
await h.parserIdle();
return typeAndMeasure(h, "x".repeat(90), 33);
},
};
async function typeAndMeasure(h: Harness, text: string, intervalMs: number): Promise<Metrics> {
const refresh = await h.refreshMs();
const t0 = await h.now();
const before = await h.counters();
const lat = await h.typeMeasured(text, intervalMs);
const work = Harness.delta(before, await h.counters());
const keys = text.length;
return {
...keySummary(lat, refresh),
// Counts look high (a frame re-styles after CodeMirror's measure writes), so budget the time.
styleLayoutMsPerKey: work.styleLayoutMs / keys,
scriptMsPerKey: work.scriptMs / keys,
mainThreadMsPerKey: work.taskMs / keys,
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
};
}
/**
* Wheel-scrolling a large file: frame pacing while CodeMirror renders new lines.
* `frame*` / `droppedFramesPct`: 120 px per frame (one wheel notch, ≈ 7 200 px/s,
* a fast trackpad). `fling*`: 600 px per frame, a whole screen each frame — a
* stress test without a budget.
*/
const scroll: Scenario = {
id: "scroll",
title: "Wheel-scroll a 20k-line file",
async run(h) {
await h.openFile(`${ROOT}/src/big/Scroll.ts`, tsSource(20_000, "scroll"));
await h.parserIdle();
const refresh = await h.refreshMs();
const box = (await h.page.locator(".cm-scroller").first().boundingBox())!;
await h.page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const t0 = await h.now();
const wheel = async (steps: number, dy: number) => {
await h.inPage((p) => p.startFrames());
for (let i = 0; i < steps; i++) {
// oxlint-disable-next-line no-await-in-loop -- wheel notches scroll one at a time; direction depends on the step index
await h.page.mouse.wheel(0, i < steps / 2 ? dy : -dy);
// oxlint-disable-next-line no-await-in-loop -- 16 ms between wheel notches is part of the measured frame pacing
await h.page.waitForTimeout(16);
}
await h.page.waitForTimeout(200);
return h.inPage((p) => p.stopFrames());
};
const smooth = frameSummary(await wheel(160, 120), refresh);
const tbtMs = totalBlockingTime(await h.longTasksSince(t0));
const fling = frameSummary(await wheel(60, 600), refresh);
// Jump far: document-end repositioning.
await h.setCursor(0);
const jumpMs = await h.jumpToEnd();
return {
...smooth,
tbtMs,
flingFrameP95Ms: fling.frameP95Ms,
flingDroppedFramesPct: fling.droppedFramesPct,
jumpMs,
};
},
};
/**
* Runs an action without a default shortcut from a key press: the press is the measured input,
* and the action runs in its handler, as from a key binding. Pause is bound to nothing.
*/
async function runActionOnKey(h: Harness, id: string) {
await h.page.evaluate((id) => {
const probe = (window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf;
addEventListener("keydown", () => void probe.runAction(id), { capture: true, once: true });
}, id);
await h.page.keyboard.press("Pause");
}
/**
* Git Log with 20,000 commits on branching lanes, loaded page by page as the
* backend does (150 ms a page, like `git log`): showing it, walking the
* selection with the arrow keys (the details pane follows) and wheel-scrolling
* through several pages.
*/
const gitLog: Scenario = {
id: "gitLog",
title: "Show, navigate and scroll a 20k-commit Git Log",
async run(h) {
await h.page.evaluate(() =>
(
window as never as { __openideaPerf: { fakeGitLog(n: number, latencyMs?: number): void } }
).__openideaPerf.fakeGitLog(20_000, 150),
);
const showMs = await h.measure(
() => runActionOnKey(h, "vcs.showLog"),
'[role="listbox"][aria-label="Commits"]',
"order flow step 0",
);
const refresh = await h.refreshMs();
const list = h.page.getByRole("listbox", { name: "Commits" });
await list.getByRole("option").first().click();
const keyLat = await h.pressMeasured(Array(40).fill("ArrowDown"), 50);
const box = (await list.boundingBox())!;
await h.page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const t0 = await h.now();
await h.inPage((p) => p.startFrames());
// Far enough to load several more pages on the way.
for (let i = 0; i < 160; i++) {
// oxlint-disable-next-line no-await-in-loop -- wheel notches must scroll in order to load several Git Log pages
await h.page.mouse.wheel(0, i < 120 ? 600 : -600);
// oxlint-disable-next-line no-await-in-loop -- 16 ms between wheel notches is part of the measured frame pacing
await h.page.waitForTimeout(16);
}
await h.page.waitForTimeout(200);
const frames = await h.inPage((p) => p.stopFrames());
return {
showMs,
...frameSummary(frames, refresh),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
...keySummary(keyLat, refresh, "arrowKey"),
};
},
};
/** Scrollbar-sized jumps across a loaded graph, rather than incremental wheel scrolling. */
const gitLogScrollbar: Scenario = {
id: "gitLogScrollbar",
title: "Drag through a loaded 6k-commit Git Log",
async run(h) {
await h.page.evaluate(async () => {
const probe = (
window as never as {
__openideaPerf: {
fakeGitLog(n: number): void;
runAction(id: string): Promise<boolean>;
};
}
).__openideaPerf;
probe.fakeGitLog(6000);
await probe.runAction("vcs.showLog");
});
const list = h.page.getByRole("listbox", { name: "Commits" });
await list.waitFor();
await list.evaluate(async (element) => {
for (let i = 0; i < 300 && element.scrollHeight < 6000 * 26; i++) {
element.scrollTop = element.scrollHeight;
// oxlint-disable-next-line no-await-in-loop -- each scroll to the bottom waits a frame for the fake log to load more rows
await new Promise(requestAnimationFrame);
}
if (element.scrollHeight < 6000 * 26) throw new Error("Git Log did not finish loading");
element.scrollTop = 0;
});
await h.page.waitForTimeout(200);
const refresh = await h.refreshMs();
const t0 = await h.now();
await h.inPage((p) => p.startFrames());
await list.evaluate(async (element) => {
const max = element.scrollHeight - element.clientHeight;
for (let i = 0; i < 180; i++) {
element.scrollTop = ((i < 90 ? i : 180 - i) / 90) * max;
// oxlint-disable-next-line no-await-in-loop -- scrollbar drag advances one position per frame
await new Promise(requestAnimationFrame);
}
});
const frames = await h.inPage((p) => p.stopFrames());
return {
...frameSummary(frames, refresh),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
};
},
};
/**
* Dragging the splitters with an editor, the Project tree and the Git Log
* open: every pointer move resizes the islands, so each frame relays them out.
*/
const resizePanels: Scenario = {
id: "resizePanels",
title: "Drag the tool window splitters",
async run(h) {
await h.openFile(SAMPLE);
await h.page.evaluate(() =>
(window as never as { __openideaPerf: { fakeGitLog(n: number): void } }).__openideaPerf.fakeGitLog(2_000),
);
await h.page.evaluate(() =>
(window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf.runAction(
"vcs.showLog",
),
);
// Set-up, not measured: the splitters are dragged once the log is shown.
await h.inPage((p) => p.waitShown('[role="listbox"][aria-label="Commits"]', "order flow step 0", 10_000));
const refresh = await h.refreshMs();
const drag = async (name: string, dx: number, dy: number) => {
const box = (await h.page.getByRole("separator", { name }).boundingBox())!;
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await h.page.mouse.move(x, y);
await h.page.mouse.down();
await h.inPage((p) => p.startFrames());
// Out and back twice, one pointer move a frame.
for (let i = 0; i < 120; i++) {
const t = Math.sin((i / 60) * Math.PI);
// oxlint-disable-next-line no-await-in-loop -- pointer moves follow the drag path one frame at a time
await h.page.mouse.move(x + dx * t, y + dy * t);
// oxlint-disable-next-line no-await-in-loop -- 16 ms between pointer moves is part of the measured drag pacing
await h.page.waitForTimeout(16);
}
await h.page.mouse.up();
await h.page.waitForTimeout(200);
return frameSummary(await h.inPage((p) => p.stopFrames()), refresh);
};
const t0 = await h.now();
const side = await drag("Resize left tool window", 300, 0);
const bottom = await drag("Resize bottom tool window", 0, -250);
return {
...side,
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
bottomFrameP95Ms: bottom.frameP95Ms,
bottomDroppedFramesPct: bottom.droppedFramesPct,
};
},
};
/** Cold load: navigation → Project tree painted. */
const startup: Scenario = {
id: "startup",
title: "Load the workbench",
blank: true,
async run(h) {
const readyMs = await h.load();
const paints = await h.page.evaluate(() =>
Object.fromEntries(performance.getEntriesByType("paint").map((e) => [e.name, e.startTime])),
);
await h.gc();
const nodes = (await h.counters()).Nodes ?? NaN;
return {
readyMs,
fcpMs: paints["first-contentful-paint"] ?? NaN,
tbtMs: totalBlockingTime(await h.longTasksSince(0)),
heapMb: await h.heapMb(),
domNodes: nodes,
};
},
};
/** Opening files: small sample, then switching between eight open tabs. */
const tabs: Scenario = {
id: "tabs",
title: "Open files and switch tabs",
async run(h) {
const openSmallMs = await h.openFile(SAMPLE);
const names: string[] = [];
for (let i = 0; i < 8; i++) {
const name = `Module${i}.ts`;
names.push(name);
// oxlint-disable-next-line no-await-in-loop -- opening files seeds and shows them in one shared editor; tab order matters
await h.openFile(`${ROOT}/src/tabs/${name}`, tsSource(2_000, `tab-${i}`));
}
const switches: number[] = [];
// Recently shown tabs keep their editor view: showing one again must not build a new one.
let viewsRebuilt = 0;
let switchWork = await h.counters();
for (let round = 0; round < 3; round++) {
// oxlint-disable-next-line no-await-in-loop -- counters are snapshotted between rounds, not concurrently with the switches
if (round === 1) switchWork = await h.counters();
for (let i = 0; i < names.length; i++) {
const tab = h.page.getByRole("tab", { name: names[i], exact: true });
// oxlint-disable-next-line no-await-in-loop -- each tab click is measured with its own armed page token; a concurrent click would cross-match the previous target
switches.push(await h.measure(() => tab.click(), ".cm-content", `// tab-${i}`));
// oxlint-disable-next-line no-await-in-loop -- view freshness must be checked right after this tab's measured click
const fresh = await h.page.evaluate(() => {
const view = document.querySelector("[data-editor-host] .cm-editor") as { perfSeen?: boolean } | null;
if (!view || view.perfSeen) return false;
view.perfSeen = true;
return true;
});
if (round > 0 && fresh) viewsRebuilt++;
}
}
const work = Harness.delta(switchWork, await h.counters());
// The Switcher (Ctrl+Tab) back and forth between the two most recent tabs.
const before = await h.counters();
const switcher: number[] = [];
for (let i = 0; i < 10; i++) {
const tag = i % 2 ? names.length - 1 : names.length - 2;
// oxlint-disable-next-line no-await-in-loop -- Switcher toggles are measured in order between the two most recent tabs
switcher.push(await h.measure(() => h.pressAction("navigate.switcher"), ".cm-content", `// tab-${tag}`));
// oxlint-disable-next-line no-await-in-loop -- 150 ms settle between Switcher toggles is part of the measured sequence
await h.page.waitForTimeout(150);
}
const switcherWork = Harness.delta(before, await h.counters());
return {
openSmallMs,
...latencySummary(switches, "switch"),
switchMainThreadMs: work.taskMs / (names.length * 2),
viewsRebuilt,
...latencySummary(switcher, "switcher"),
switcherMainThreadMs: switcherWork.taskMs / switcher.length,
};
},
};
/**
* Two agent tasks with long conversations (150 turns, 2,100 entries) in editor tabs:
* switching between them with the Switcher (Ctrl+Tab) shows a kept-alive conversation
* again, which must not restyle its whole history; then scrolling up through one.
* Chromium anchors scrolling on its own (WebKit doesn't), so anchoring is turned off
* here: rows that take their real height only once scrolled into view would jump.
*/
const agentTabs: Scenario = {
id: "agentTabs",
title: "Switch between and scroll long agent conversations",
async run(h) {
await h.page.addStyleTag({ content: "* { overflow-anchor: none !important; }" });
await h.page.evaluate(() =>
(
window as never as { __openideaPerf: { runAction(id: string, arg?: unknown): Promise<boolean> } }
).__openideaPerf.runAction("agents.openSampleConversations", { tasks: 2, turns: 150 }),
);
// The conversation shown: its requests end with its task's title.
const SHOWN = "[data-editor-focus] [data-message]";
const title = (n: number) => `(Sample task ${n})`;
// Visit each conversation to let it finish painting and laying out its history.
for (const n of [1, 2]) {
// oxlint-disable-next-line no-await-in-loop -- visit conversations in order so each history is laid out before the next
await h.page.getByRole("tab", { name: `Sample task ${n}` }).click();
// oxlint-disable-next-line no-await-in-loop -- wait for this tab's conversation to attach before it can settle
await h.page
.locator(SHOWN, { hasText: title(n) })
.filter({ hasText: "Turn 0:" })
.first()
.waitFor({ state: "attached", timeout: 30_000 });
// oxlint-disable-next-line no-await-in-loop -- settle wait belongs to this tab's visit, before the next tab
await h.page.waitForTimeout(300);
}
// WebKit restyles a hidden conversation in full when it is shown again (Chromium keeps its
// style): what bounds that there is the history's DOM, and rows skipping rendering off screen.
const { conversationNodes, rowsAlwaysRendered } = await h.page.evaluate((selector) => {
const conversation = document.querySelector(selector)!;
const rows = [...conversation.querySelector("[data-message]")!.parentElement!.children];
return {
conversationNodes: conversation.querySelectorAll("*").length,
rowsAlwaysRendered: rows.filter((r) => getComputedStyle(r).contentVisibility !== "auto").length,
};
}, "[data-editor-focus]");
const t0 = await h.now();
const before = await h.counters();
const switches: number[] = [];
for (let i = 0; i < 10; i++) {
// oxlint-disable-next-line no-await-in-loop -- Switcher toggles are measured in order between the two conversations
switches.push(await h.measure(() => h.pressAction("navigate.switcher"), SHOWN, title(i % 2 ? 2 : 1)));
// oxlint-disable-next-line no-await-in-loop -- 150 ms settle between Switcher toggles is part of the measured sequence
await h.page.waitForTimeout(150);
}
const work = Harness.delta(before, await h.counters());
const switchTbtMs = totalBlockingTime(await h.longTasksSince(t0));
// Scrolling up from the end, a step at a time: how far the text under the pointer moves
// beyond the scroll itself.
const scrollJumps = await h.page.evaluate(async (selector) => {
const stream = document.querySelector(selector)!.parentElement!;
const frame = () => new Promise(requestAnimationFrame);
stream.scrollTop = stream.scrollHeight;
await frame();
await frame();
const top = stream.getBoundingClientRect().top;
let jumps = 0;
for (let i = 0; i < 100 && stream.scrollTop > 0; i++) {
const row = [...stream.children].find((r) => r.getBoundingClientRect().bottom > top + 200)!;
const from = row.getBoundingClientRect().top;
const scrolled = stream.scrollTop;
// A wheel step: the user scrolls, so the conversation stops following its end.
stream.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -120 }));
stream.scrollTop -= 120;
const by = scrolled - stream.scrollTop;
// oxlint-disable-next-line no-await-in-loop -- two frame ticks per fake wheel step; row movement is read after them
await frame();
// oxlint-disable-next-line no-await-in-loop -- the second frame tick completes this step before its jump is measured
await frame();
if (Math.abs(row.getBoundingClientRect().top - from - by) > 2) jumps++;
}
stream.scrollTop = stream.scrollHeight;
return jumps;
}, SHOWN);
const refresh = await h.refreshMs();
const box = (await h.page.locator("[data-editor-focus]").boundingBox())!;
await h.page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await h.page.waitForTimeout(200);
const t1 = await h.now();
await h.inPage((p) => p.startFrames());
for (let i = 0; i < 120; i++) {
// oxlint-disable-next-line no-await-in-loop -- wheel steps scroll the conversation up one at a time
await h.page.mouse.wheel(0, -120);
// oxlint-disable-next-line no-await-in-loop -- 16 ms between wheel steps is part of the measured frame pacing
await h.page.waitForTimeout(16);
}
await h.page.waitForTimeout(200);
const scroll = frameSummary(await h.inPage((p) => p.stopFrames()), refresh);
return {
conversationNodes,
rowsAlwaysRendered,
...latencySummary(switches, "switch"),
switchMainThreadMs: work.taskMs / switches.length,
switchStyleLayoutMs: work.styleLayoutMs / switches.length,
switchTbtMs,
scrollJumps,
scrollFrameP95Ms: scroll.frameP95Ms,
scrollDroppedFramesPct: scroll.droppedFramesPct,
scrollTbtMs: totalBlockingTime(await h.longTasksSince(t1)),
};
},
};
/** Find Action and Search Everywhere: open, then query → first result painted. */
const popups: Scenario = {
id: "popups",
title: "Find Action / Search Everywhere",
async run(h) {
await h.openFile(SAMPLE);
const findActionOpenMs = await h.measure(() => h.pressAction("navigate.findAction"), '[role="dialog"] input');
const findActionQueryMs = await h.measure(
() => h.page.keyboard.insertText("memory indicator"),
'[role="dialog"] [role="option"]',
"Memory Indicator",
);
// Editing the query: Backspace → list re-filtered and painted.
const refresh = await h.refreshMs();
const keyLat = await h.typeMeasured("\b\b\b\b\b\b", 80, "input");
await h.page.keyboard.press("Escape");
await h.page.locator('[role="dialog"]').waitFor({ state: "detached" });
const seOpenMs = await h.measure(
() => h.pressAction("navigate.searchEverywhere"),
'[role="dialog"][aria-label="Search Everywhere"] input',
);
const seQueryMs = await h.measure(
() => h.page.keyboard.insertText("language servers"),
'[role="dialog"] [role="option"]',
"Language Servers",
);
await h.page.keyboard.press("Escape");
return {
findActionOpenMs,
findActionQueryMs,
...keySummary(keyLat, refresh, "findActionKey"),
searchEverywhereOpenMs: seOpenMs,
searchEverywhereQueryMs: seQueryMs,
};
},
};
const TOOL_WINDOWS: Array<[string, string]> = [
["toolwindow.problems", "Problems"],
["toolwindow.run", "Run"],
["toolwindow.structure", "Structure"],
["toolwindow.commit", "Commit"],
["toolwindow.git", "Git"],
["toolwindow.terminal", "Terminal"],
];
/** Showing tool windows by shortcut (first show loads and mounts the view). */
const toolWindows: Scenario = {
id: "toolWindows",
title: "Show tool windows",
async run(h) {
await h.openFile(SAMPLE);
const m: Metrics = {};
const all: number[] = [];
for (const [action, title] of TOOL_WINDOWS) {
// Until the view's content is laid out (lazily loaded views render nothing at first).
// oxlint-disable-next-line no-await-in-loop -- tool windows are shown and measured one at a time in the shared page
const ms = await h.measure(
() => h.pressAction(action),
`section[aria-label="${title}"] [data-toolwindow-body] > *`,
);
m[`${title.toLowerCase()}Ms`] = ms;
all.push(ms);
// oxlint-disable-next-line no-await-in-loop -- hide this window before showing the next one
await h.pressAction(action);
// oxlint-disable-next-line no-await-in-loop -- wait for the hide before the next measurement starts
await h.page.locator(`section[aria-label="${title}"]`).waitFor({ state: "hidden" });
}
return { maxMs: Math.max(...all), ...m };
},
};
/** Project tree: expand a 10 000-entry folder and scroll through it. */
const projectTree: Scenario = {
id: "projectTree",
title: "Expand and scroll a 10k-entry folder",
async run(h) {
const generated = h.page.locator('[role="treeitem"][aria-level="2"]', { hasText: "generated" }).first();
await generated.click();
// Measure from a settled selection: a key pressed in the click's own frame also pays for that frame.
await generated.and(h.page.locator('[aria-selected="true"]')).waitFor();
await h.page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
const expandMs = await h.measure(
() => h.page.keyboard.press("ArrowRight"),
'[role="tree"][aria-label="Project"]',
"item1.json",
);
const refresh = await h.refreshMs();
// Selection walks into the expanded folder (rows stay rendered: no scroll yet).
const keyLat = await h.pressMeasured(Array(30).fill("ArrowDown"), 50);
const box = (await h.page.getByRole("tree", { name: "Project" }).boundingBox())!;
await h.page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const t0 = await h.now();
await h.inPage((p) => p.startFrames());
for (let i = 0; i < 60; i++) {
// oxlint-disable-next-line no-await-in-loop -- wheel steps scroll the tree one at a time
await h.page.mouse.wheel(0, 500);
// oxlint-disable-next-line no-await-in-loop -- 16 ms between wheel steps is part of the measured frame pacing
await h.page.waitForTimeout(16);
}
await h.page.waitForTimeout(200);
const frames = await h.inPage((p) => p.stopFrames());
return {
expandMs,
...frameSummary(frames, refresh),
tbtMs: totalBlockingTime(await h.longTasksSince(t0)),
...keySummary(keyLat, refresh, "arrowKey"),
};
},
};
/**
* Selects from `item<first>.json` of the 10 000-entry folder to the end of the tree (speed search,
* Escape, Shift+End), then presses Copy and Delete. `items`: the count the Delete dialog shows;
* `copyMs`: key → next frame; `deleteMs`: key → dialog shown (then cancelled).
*/
async function copyAndDelete(h: Harness, first: number) {
const tree = h.page.getByRole("tree", { name: "Project" });
await h.page.keyboard.type(`item${first}.json`);
await tree.getByRole("treeitem", { name: `item${first}.json`, exact: true, selected: true }).waitFor();
await h.page.keyboard.press("Escape");
await h.page.keyboard.press("Shift+End");
await h.page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
// Hold the modifiers first: only the main key's keydown is measured.
const [copyKey] = await h.keysFor("project.copy");
const mods = copyKey!.split("+");
const key = mods.pop()!;
// oxlint-disable-next-line no-await-in-loop -- modifiers go down (and up) one at a time
for (const m of mods) await h.page.keyboard.down(m);
const [copyMs] = await h.pressMeasured([key], 50);
// oxlint-disable-next-line no-await-in-loop -- modifiers go down (and up) one at a time
for (const m of mods) await h.page.keyboard.up(m);
const deleteMs = await h.measure(
() => h.pressAction("project.delete"),
'[role="dialog"]',
"Items are moved to the Trash.",
120_000,
);
const dialog = h.page.getByRole("dialog", { name: "Delete", exact: true });
const text = (await dialog.textContent()) ?? "";
const items = Number(/Delete (\d+) items/.exec(text)?.[1]);
if (!items) throw new Error(`unexpected Delete dialog: ${text}`);
await h.page.keyboard.press("Escape");
await dialog.waitFor({ state: "hidden" });
return { items, copyMs: copyMs!, deleteMs };
}
/** Project tree: Copy and Delete on about 10, 1 000, 5 000 and 10 000 selected rows. */
const projectTreeSelection: Scenario = {
id: "projectTreeSelection",
title: "Copy and Delete thousands of selected tree rows",
async run(h) {
const generated = h.page.locator('[role="treeitem"][aria-level="2"]', { hasText: "generated" }).first();
await generated.click();
await generated.and(h.page.locator('[aria-selected="true"]')).waitFor();
await h.page.keyboard.press("ArrowRight");
await h.page.getByRole("treeitem", { name: "item1.json", exact: true }).waitFor();
const out: Metrics = {};
for (const [label, first] of [
["10", 9995],
["1k", 9001],
["5k", 5001],
["All", 1],
] as const) {
// oxlint-disable-next-line no-await-in-loop -- one selection at a time in the same tree
const m = await copyAndDelete(h, first);
out[`items${label}`] = m.items;
out[`copy${label}Ms`] = m.copyMs;
out[`delete${label}Ms`] = m.deleteMs;
}
return out;
},
};
/** Files in the `combinedDiff` scenarios (`OPENIDEA_PERF_COMBINED_FILES`). */
const COMBINED_FILES = Number(process.env.OPENIDEA_PERF_COMBINED_FILES ?? 500);
/** Farthest the wheel pass scrolls before turning back: about 100 files of 40 lines. */
const COMBINED_WHEEL_PX = 100_000;
/**
* Opens an all-in-one diff of `COMBINED_FILES` files from a key press, then scrolls down and back
* up, for at most 60 s each way. `wheel`: 120 px per 16 ms of wall time (a fast wheel; the
* compositor keeps scrolling through a slow frame), down to the end or `COMBINED_WHEEL_PX`.
* `stress`: a viewport (or 1/300 of the whole height, if more) a frame, down to the end.
* `blankFrames`: frames whose viewport centre shows neither a diff nor a file header.
* `slowFrameMs` / `slowTimePct`: time in frames over 33 ms, and its share of the scroll time:
* shares of frame counts mislead when one side renders far fewer, longer frames.
*/
async function combinedDiffScroll(h: Harness, mode: "wheel" | "stress") {
// Opened from a key press, the measured input (no default shortcut opens it).
await h.page.evaluate((n) => {
const w = window as never as {
__openideaPerf: { openCombinedDiff(n: number): Promise<{ first: string; last: string }> };
__combinedPaths?: Promise<{ first: string; last: string }>;
};
addEventListener("keydown", () => (w.__combinedPaths = w.__openideaPerf.openCombinedDiff(n)), {
capture: true,
once: true,
});
}, COMBINED_FILES);
const openMs = await h.measure(
() => h.page.keyboard.press("Pause"),
"[data-combined-scroll] .cm-content",
null,
30_000,
);
const paths = await h.page.evaluate(
() => (window as never as { __combinedPaths: Promise<{ first: string; last: string }> }).__combinedPaths,
);
await h.page.waitForTimeout(500);
const refresh = await h.refreshMs();
const t0 = await h.now();
await h.inPage((p) => p.startFrames());
const pass = await h.page.locator("[data-combined-scroll]").evaluate(
async (el, { first, last, wheel, maxPx }) => {
const editors = () => el.querySelectorAll(".cm-editor").length;
const box = el.getBoundingClientRect();
const blank = () => {
const hit = document.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2);
return !hit?.closest(".cm-editor, [data-combined-block] > :first-child");
};
const shown = (path: string) => !!el.querySelector(`[data-combined-block="${CSS.escape(path)}"]`);
const step = () => Math.max(el.clientHeight, Math.ceil((el.scrollHeight - el.clientHeight) / 300));
let peakEditors = editors();
let blankFrames = 0;
let frames = 0;
let reachedEnd = false;
const walk = async (down: boolean) => {
const started = performance.now();
const from = el.scrollTop;
// The end only once the view has stayed there for 30 frames: blocks loading near the bottom
// still grow the view, so a first touch of the bottom isn't the end of the whole change.
let settled = 0;
while (performance.now() - started < 60_000) {
const atEnd = el.scrollTop + el.clientHeight >= el.scrollHeight - 1 && shown(last);
settled = down && atEnd ? settled + 1 : 0;
if (settled >= 30) reachedEnd = true;
if (down ? reachedEnd || (wheel && el.scrollTop - from >= maxPx) : el.scrollTop <= 0 && shown(first))
return true;
const moved = wheel ? ((performance.now() - started) * 120) / 16 : 0;
if (wheel) el.scrollTop = down ? Math.min(from + moved, from + maxPx) : Math.max(0, from - moved);
else el.scrollTop = down ? el.scrollTop + step() : Math.max(0, el.scrollTop - step());
// oxlint-disable-next-line no-await-in-loop -- rAF ticks advance the simulated scroll and its frame counters together
await new Promise(requestAnimationFrame);
frames++;
if (blank()) blankFrames++;
peakEditors = Math.max(peakEditors, editors());
}
return false;
};
await walk(true);
const scrolledPx = el.scrollTop;
const backAtTop = await walk(false);
return { reachedEnd, backAtTop, scrolledPx, peakEditors, blankFrames, frames };
},
{ ...paths, wheel: mode === "wheel", maxPx: COMBINED_WHEEL_PX },
);
const frames = await h.inPage((p) => p.stopFrames());
const tbtMs = totalBlockingTime(await h.longTasksSince(t0));
const slow = frames.filter((f) => f > 33);
const slowFrameMs = slow.reduce((sum, f) => sum + f, 0);
const totalMs = frames.reduce((sum, f) => sum + f, 0);
return {
openMs,
...frameSummary(frames, refresh),
slowFramesPct: frames.length ? (100 * slow.length) / frames.length : 0,
slowFrameMs,
slowTimePct: totalMs ? (100 * slowFrameMs) / totalMs : 0,
tbtMs,
peakEditors: pass.peakEditors,
blankFrames: pass.blankFrames,
scrollFrames: pass.frames,
blankPct: pass.frames ? (100 * pass.blankFrames) / pass.frames : 0,
scrolledPx: pass.scrolledPx,
reachedEnd: pass.reachedEnd ? 1 : 0,
backAtTop: pass.backAtTop ? 1 : 0,
domNodes: (await h.counters()).Nodes ?? NaN,
};
}
const combinedDiff: Scenario = {
id: "combinedDiff",
title: `Wheel through an all-in-one diff of ${COMBINED_FILES} files`,
run: (h) => combinedDiffScroll(h, "wheel"),
};
const combinedDiffStress: Scenario = {
id: "combinedDiffStress",
title: `Scroll an all-in-one diff of ${COMBINED_FILES} files a screen a frame`,
run: (h) => combinedDiffScroll(h, "stress"),
};
/** Opening and closing editors repeatedly must not grow the heap or the DOM. */
const leaks: Scenario = {
id: "leaks",
title: "Open / close 10 editors × 4",
async run(h) {
const cycle = async (n: number) => {
for (let i = 0; i < 10; i++)
// oxlint-disable-next-line no-await-in-loop -- files open into one shared editor; parallel opens would race on its state
await h.openFile(`${ROOT}/src/leak/File${n}_${i}.ts`, tsSource(1_500, `leak-${n}-${i}`));
await h.page.evaluate(() =>
(window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf.runAction(
"editor.closeAllTabs",
),
);
await h.page.locator(".cm-editor").waitFor({ state: "detached" });
};
await cycle(0);
await h.gc();
const heap0 = await h.heapMb();
const c0 = await h.counters();
// oxlint-disable-next-line no-await-in-loop -- leak cycles run one after another; parallel cycles would invalidate heap growth
for (let n = 1; n <= 3; n++) await cycle(n);
await h.gc();
const c1 = await h.counters();
return {
heapGrowthMb: (await h.heapMb()) - heap0,
domNodeGrowth: (c1.Nodes ?? 0) - (c0.Nodes ?? 0),
listenerGrowth: (c1.JSEventListeners ?? 0) - (c0.JSEventListeners ?? 0),
};
},
};
export const SCENARIOS: Scenario[] = [
startup,
typing,
typingLarge,
typingAngular,
completion,
consoleOutput,
consoleLongLines,
terminalTui,
gitLog,
gitLogScrollbar,
resizePanels,
keyRepeat,
scroll,
tabs,
agentTabs,
popups,
toolWindows,
projectTree,
projectTreeSelection,
combinedDiff,
combinedDiffStress,
leaks,
];