chore(web): measure renders before/after with render scenarios #24980
Mergedjuliusmarmingemerged 1 commit into
main fromrefs/pull/24980/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -0,0 +182,21 @@182+ counts.effects += 1;183+ const [callback, depsArgument] = node.arguments;184+ if (!depsArgument) counts.noDeps += 1;185+ const deps =186+ depsArgument && ts.isArrayLiteralExpression(depsArgument)187+ ? new Set(depsArgument.elements.map((element) => rootIdentifier(element) ?? ""))188+ : null;189+ const setStates = new Set<string>();190+ let sync = false;191+ if (callback && isFunctionLike(callback) && callback.body) {192+ const body = callback.body;193+ forEachInline(body, (inner) => {194+ if (195+ ts.isCallExpression(inner) &&196+ (calledSetter(inner, bindings) || isStoreWrite(inner))197+ ) {198+ sync = true;199+ }200+ });201+ forEachDeep(body, (inner) => {202+ const setter = ts.isCallExpression(inner) ? calledSetter(inner, bindings) : null;@@ -0,0 +21,21 @@21+its counted window, so layout follow-ups are included.22+23+Comparing two refs needs both checkouts, since the scenarios run each tree's code:24+ node scripts/render-metrics.ts run --out ../main-renders.json # on main25+ node scripts/render-metrics.ts run --out ../branch-renders.json # on the branch26+ node scripts/render-metrics.ts compare ../main-renders.json ../branch-renders.json27+A second checkout comes from \`git worktree add ../<name> main\`; copy the harness files28+in if that tree predates them.`;29+30+export interface ScenarioReport {31+ /** null where a scenario's commit count depends on frame timing. */32+ readonly commits: number | null;33+ readonly renders: number;34+ readonly components: Readonly<Record<string, number>>;35+}36+export type RenderMetrics = Readonly<Record<string, ScenarioReport>>;37+38+const root = NodePath.resolve(import.meta.dirname, "..");39+40+function runOnce(): RenderMetrics {41+ const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.homedir(), ".cache", "t3-renders-"));
- @@ -0,0 +184,21 @@184+ if (!depsArgument) counts.noDeps += 1;185+ const deps =186+ depsArgument && ts.isArrayLiteralExpression(depsArgument)187+ ? new Set(depsArgument.elements.map((element) => rootIdentifier(element) ?? ""))188+ : null;189+ const setStates = new Set<string>();190+ let sync = false;191+ if (callback && isFunctionLike(callback) && callback.body) {192+ const body = callback.body;193+ forEachInline(body, (inner) => {194+ if (195+ ts.isCallExpression(inner) &&196+ (calledSetter(inner, bindings) || isStoreWrite(inner))197+ ) {198+ sync = true;199+ }200+ });201+ forEachDeep(body, (inner) => {202+ const setter = ts.isCallExpression(inner) ? calledSetter(inner, bindings) : null;203+ if (setter) setStates.add(bindings.setterToState.get(setter) ?? "");204+ });@@ -0,0 +21,21 @@21+its counted window, so layout follow-ups are included.22+23+Comparing two refs needs both checkouts, since the scenarios run each tree's code:24+ node scripts/render-metrics.ts run --out ../main-renders.json # on main25+ node scripts/render-metrics.ts run --out ../branch-renders.json # on the branch26+ node scripts/render-metrics.ts compare ../main-renders.json ../branch-renders.json27+A second checkout comes from \`git worktree add ../<name> main\`; copy the harness files28+in if that tree predates them.`;29+30+export interface ScenarioReport {31+ /** null where a scenario's commit count depends on frame timing. */32+ readonly commits: number | null;33+ readonly renders: number;34+ readonly components: Readonly<Record<string, number>>;35+}36+export type RenderMetrics = Readonly<Record<string, ScenarioReport>>;37+38+const root = NodePath.resolve(import.meta.dirname, "..");39+40+function runOnce(): RenderMetrics {41+ const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.homedir(), ".cache", "t3-renders-"));@@ -0,0 +49,21 @@49+ const files = NodeFS.readdirSync(directory)50+ .filter((file) => file.endsWith(".json"))51+ .toSorted();52+ return Object.fromEntries(53+ files.map((file) => [54+ file.replace(/\.json$/, ""),55+ JSON.parse(NodeFS.readFileSync(NodePath.join(directory, file), "utf8")) as ScenarioReport,56+ ]),57+ );58+ } finally {59+ NodeFS.rmSync(directory, { recursive: true, force: true });60+ }61+}62+63+/** Scenarios whose counts differ between runs, by name. */64+export function nondeterministic(runs: ReadonlyArray<RenderMetrics>): string[] {65+ const [first, ...rest] = runs;66+ if (!first) return [];67+ return Object.keys(first).filter((scenario) =>68+ rest.some((run) => JSON.stringify(run[scenario]) !== JSON.stringify(first[scenario])),69+ );@@ -0,0 +102,21 @@102+ .sort(([n, x, y], [m, p, q]) => Math.abs(q - p) - Math.abs(y - x) || n.localeCompare(m))103+ .slice(0, top);104+ if (moved.length === 0) continue;105+ lines.push("", `<details><summary>${scenario}: components that changed most</summary>`, "");106+ lines.push("| component | renders |", "| :-- | --: |");107+ for (const [name, x, y] of moved) lines.push(`| \`${name}\` | ${change(x, y)} |`);108+ lines.push("", "</details>");109+ }110+ return lines.join("\n");111+}112+113+function option(args: ReadonlyArray<string>, name: string): string | undefined {114+ const index = args.indexOf(name);115+ return index === -1 ? undefined : args[index + 1];116+}117+118+if (import.meta.main) {119+ const [command, ...args] = process.argv.slice(2);120+ if (command === "run") {121+ const runs = Number(option(args, "--runs") ?? 3);122+ const results = Array.from({ length: runs }, runOnce);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge changed the title
- @@ -0,0 +178,21 @@178+ payload: userItem(LIVE, live.id, "live-user", HISTORY_TURNS * 2, "Continue"),179+ });180+ });181+ await expect.element(page.getByText("Continue", { exact: true })).toBeVisible();182+ const counted = await measure(async () => {183+ let text = "";184+ for (let delta = 0; delta < STREAM_DELTAS; delta++) {185+ text += `word${delta} `;186+ await act(() =>187+ emitThreadEvent(LIVE, {188+ type: "turn-item.updated",189+ payload: assistantItem(190+ LIVE,191+ live.id,192+ "live-assistant",193+ HISTORY_TURNS * 2 + 1,194+ text,195+ true,196+ ),197+ }),198+ );
juliusmarminge merged this2dfd6bf
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed