Skip to content

Commit fe659c2

Browse files
authored
perf(app): review benches start every run from the same storage, and click Next once the pane rests (anomalyco#62311)
1 parent c62357a commit fe659c2

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎packages/app/perf/diff.bench.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { bench, web, type Case } from "@hona/strobe"
44
import { reviewDiffs, routesDiff } from "./fixtures/diffs"
55
import { cached } from "./fixtures/mock"
66
import { openReview, review } from "./fixtures/review"
7+
import { keepStartStorage, saveStartStorage } from "./fixtures/storage"
78
import { mockTimelineSession, serveDiffs, timeline } from "./fixtures/timeline"
89

910
// The pane opening on the diff, in a fresh document each run.
@@ -28,6 +29,7 @@ export default bench({
2829
async prepare(ctx) {
2930
const { case: name, url } = ctx
3031
const page = cached(ctx)
32+
await keepStartStorage(page)
3133
const session = await mockTimelineSession(page, { server: new URL(url).origin, historyTurns: 0 })
3234
await serveDiffs(page, changes(name))
3335

@@ -43,6 +45,8 @@ export default bench({
4345
// The long diff rendered once, then the pane moved to another file.
4446
if (name === "return to a long diff") {
4547
await openReview(page)
48+
// The pane widens to fit the diff after its first file shows, which moves Next: click it once the pane rests.
49+
await page.idle()
4650
await page.click(review.next)
4751
await page.waitFor(review.file, { text: "routes.ts" })
4852
await page.waitFor(review.line)
@@ -51,6 +55,8 @@ export default bench({
5155
}
5256

5357
await page.idle()
58+
// A reload keeps the review open (the app saves its layout on pagehide), so every run starts from this storage.
59+
await saveStartStorage(page)
5460
},
5561

5662
cases: {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Page } from "@hona/strobe"
2+
import type { Page as PlaywrightPage } from "@playwright/test"
3+
4+
const KEY = "perf.start-storage"
5+
6+
/**
7+
* Every later document starts from the local storage that `saveStartStorage` recorded. The app writes its layout (the
8+
* review pane open, its tab) on pagehide, so without this a reset's reload would carry what the run opened into the
9+
* next run.
10+
*/
11+
export async function keepStartStorage(page: Pick<PlaywrightPage, "addInitScript">) {
12+
await page.addInitScript((key) => {
13+
const saved = sessionStorage.getItem(key)
14+
15+
if (saved === null) return
16+
17+
localStorage.clear()
18+
19+
// SAFETY: only saveStartStorage writes this key, as an object of localStorage's own strings.
20+
const entries = Object.entries(JSON.parse(saved) as Record<string, string>)
21+
22+
for (const [name, value] of entries) localStorage.setItem(name, value)
23+
}, KEY)
24+
}
25+
26+
/** Records the local storage runs start from: call last in `setup`, once the page has loaded. */
27+
export function saveStartStorage(page: Page) {
28+
return page.eval((key) => sessionStorage.setItem(key, JSON.stringify({ ...localStorage })), KEY)
29+
}

‎packages/app/perf/review.bench.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { bench, web } from "@hona/strobe"
44
import { scalingDiffs, scalingRows } from "./fixtures/diffs"
55
import { cached } from "./fixtures/mock"
66
import { openReview, review } from "./fixtures/review"
7+
import { keepStartStorage, saveStartStorage } from "./fixtures/storage"
78
import { mockTimelineSession, serveDiffs, timeline } from "./fixtures/timeline"
89

910
export default bench({
@@ -17,6 +18,7 @@ export default bench({
1718
async prepare(ctx) {
1819
const { params, url } = ctx
1920
const page = cached(ctx)
21+
await keepStartStorage(page)
2022
const session = await mockTimelineSession(page, { server: new URL(url).origin, historyTurns: 0 })
2123
// The app asks for the changes only when the pane opens.
2224
await serveDiffs(page, scalingDiffs(params.files))
@@ -32,6 +34,8 @@ export default bench({
3234

3335
if (name !== "open review") await openReview(page)
3436
await page.idle()
37+
// A reload keeps the review open (the app saves its layout on pagehide), so every run starts from this storage.
38+
await saveStartStorage(page)
3539
},
3640

3741
cases: {

0 commit comments

Comments
 (0)