perf(app): review benches start every run from the same storage, and click Next once the pane rests (#62311)

This commit is contained in:
Luke Parker
2026-11-06 09:58:37 -06:00
committed by GitHub
Unverified
parent c62357a58e
commit fe659c246f
3 changed files with 39 additions and 0 deletions
+6
View File
@@ -4,6 +4,7 @@ import { bench, web, type Case } from "@hona/strobe"
import { reviewDiffs, routesDiff } from "./fixtures/diffs"
import { cached } from "./fixtures/mock"
import { openReview, review } from "./fixtures/review"
import { keepStartStorage, saveStartStorage } from "./fixtures/storage"
import { mockTimelineSession, serveDiffs, timeline } from "./fixtures/timeline"
// The pane opening on the diff, in a fresh document each run.
@@ -28,6 +29,7 @@ export default bench({
async prepare(ctx) {
const { case: name, url } = ctx
const page = cached(ctx)
await keepStartStorage(page)
const session = await mockTimelineSession(page, { server: new URL(url).origin, historyTurns: 0 })
await serveDiffs(page, changes(name))
@@ -43,6 +45,8 @@ export default bench({
// The long diff rendered once, then the pane moved to another file.
if (name === "return to a long diff") {
await openReview(page)
// The pane widens to fit the diff after its first file shows, which moves Next: click it once the pane rests.
await page.idle()
await page.click(review.next)
await page.waitFor(review.file, { text: "routes.ts" })
await page.waitFor(review.line)
@@ -51,6 +55,8 @@ export default bench({
}
await page.idle()
// A reload keeps the review open (the app saves its layout on pagehide), so every run starts from this storage.
await saveStartStorage(page)
},
cases: {
+29
View File
@@ -0,0 +1,29 @@
import type { Page } from "@hona/strobe"
import type { Page as PlaywrightPage } from "@playwright/test"
const KEY = "perf.start-storage"
/**
* Every later document starts from the local storage that `saveStartStorage` recorded. The app writes its layout (the
* review pane open, its tab) on pagehide, so without this a reset's reload would carry what the run opened into the
* next run.
*/
export async function keepStartStorage(page: Pick<PlaywrightPage, "addInitScript">) {
await page.addInitScript((key) => {
const saved = sessionStorage.getItem(key)
if (saved === null) return
localStorage.clear()
// SAFETY: only saveStartStorage writes this key, as an object of localStorage's own strings.
const entries = Object.entries(JSON.parse(saved) as Record<string, string>)
for (const [name, value] of entries) localStorage.setItem(name, value)
}, KEY)
}
/** Records the local storage runs start from: call last in `setup`, once the page has loaded. */
export function saveStartStorage(page: Page) {
return page.eval((key) => sessionStorage.setItem(key, JSON.stringify({ ...localStorage })), KEY)
}
+4
View File
@@ -4,6 +4,7 @@ import { bench, web } from "@hona/strobe"
import { scalingDiffs, scalingRows } from "./fixtures/diffs"
import { cached } from "./fixtures/mock"
import { openReview, review } from "./fixtures/review"
import { keepStartStorage, saveStartStorage } from "./fixtures/storage"
import { mockTimelineSession, serveDiffs, timeline } from "./fixtures/timeline"
export default bench({
@@ -17,6 +18,7 @@ export default bench({
async prepare(ctx) {
const { params, url } = ctx
const page = cached(ctx)
await keepStartStorage(page)
const session = await mockTimelineSession(page, { server: new URL(url).origin, historyTurns: 0 })
// The app asks for the changes only when the pane opens.
await serveDiffs(page, scalingDiffs(params.files))
@@ -32,6 +34,8 @@ export default bench({
if (name !== "open review") await openReview(page)
await page.idle()
// A reload keeps the review open (the app saves its layout on pagehide), so every run starts from this storage.
await saveStartStorage(page)
},
cases: {