-
Notifications
You must be signed in to change notification settings - Fork 14
fix: reduce perf comparator false positives #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a19d922
fix: raise perf interaction median floor
Astro-Han d382488
fix: confirm perf failures by metric key
Astro-Han 7d19f60
test: cover perf confirm script scope
Astro-Han 3ba01b9
fix: keep missing perf scenarios in confirm scope
Astro-Han b53932e
fix: dedupe perf baseline comparison keys
Astro-Han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test" | ||
| import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises" | ||
| import { tmpdir } from "node:os" | ||
| import { join } from "node:path" | ||
| import type { PerfBaselineComparison, PerfProfile, PerfScenarioSummary } from "./perf-metrics" | ||
|
|
||
| const tempRoots: string[] = [] | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(tempRoots.splice(0).map((root) => rm(root, { recursive: true, force: true }))) | ||
| }) | ||
|
|
||
| function scenario(input: { | ||
| branch: string | ||
| profile?: PerfProfile | ||
| scenario?: string | ||
| interaction?: number | ||
| frameMax?: number | ||
| }): PerfScenarioSummary { | ||
| const interaction = input.interaction ?? 40 | ||
| return { | ||
| branch: input.branch, | ||
| profile: input.profile ?? "default", | ||
| scenario: input.scenario ?? "session-scroll-reading", | ||
| runs: 3, | ||
| interaction_ms_median: interaction, | ||
| interaction_ms_worst: interaction, | ||
| interaction_ms: interaction, | ||
| interaction_delay_ms: 0, | ||
| long_task_count: 0, | ||
| long_task_max_ms: 0, | ||
| tbt_ms: 0, | ||
| frame_gap_p95_ms: 16, | ||
| frame_gap_max_ms: input.frameMax ?? 16, | ||
| jank_count_50ms: 0, | ||
| cls: 0, | ||
| window_ms: 900, | ||
| run_details: [], | ||
| } | ||
| } | ||
|
|
||
| async function writeJson(filePath: string, payload: unknown) { | ||
| await writeFile(filePath, `${JSON.stringify(payload, null, 2)}\n`) | ||
| } | ||
|
|
||
| describe("compare-perf script", () => { | ||
| test("confirms only the initial metric failure key from failures-from", async () => { | ||
| const root = await mkdtemp(join(tmpdir(), "compare-perf-script-")) | ||
| tempRoots.push(root) | ||
| const basePath = join(root, "base.json") | ||
| const headPath = join(root, "head.json") | ||
| const initialPath = join(root, "perf-compare.json") | ||
| const outputPath = join(root, "perf-compare-confirm.json") | ||
| const initialComparison: PerfBaselineComparison = { | ||
| pass: false, | ||
| failures: ["default:session-scroll-reading:interaction_ms_median"], | ||
| warnings: [], | ||
| scenarios: [ | ||
| { | ||
| profile: "default", | ||
| scenario: "session-scroll-reading", | ||
| pass: false, | ||
| failures: ["interaction_ms_median"], | ||
| warnings: [], | ||
| base: scenario({ branch: "base", interaction: 48 }), | ||
| head: scenario({ branch: "head", interaction: 76 }), | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| await writeJson(basePath, [scenario({ branch: "base", interaction: 32, frameMax: 16 })]) | ||
| await writeJson(headPath, [scenario({ branch: "head", interaction: 40, frameMax: 120 })]) | ||
| await writeJson(initialPath, initialComparison) | ||
|
|
||
| const child = Bun.spawn( | ||
| [ | ||
| process.execPath, | ||
| "script/compare-perf.ts", | ||
| "--base", | ||
| basePath, | ||
| "--head", | ||
| headPath, | ||
| "--output", | ||
| outputPath, | ||
| "--failures-from", | ||
| initialPath, | ||
| ], | ||
| { | ||
| cwd: process.cwd(), | ||
| stderr: "pipe", | ||
| stdout: "pipe", | ||
| }, | ||
| ) | ||
| const [exitCode, stdout, stderr] = await Promise.all([ | ||
| child.exited, | ||
| new Response(child.stdout).text(), | ||
| new Response(child.stderr).text(), | ||
| ]) | ||
|
|
||
| expect(stderr).toBe("") | ||
| expect(exitCode).toBe(0) | ||
| const summary = JSON.parse(stdout) as Pick<PerfBaselineComparison, "confirmation" | "failures" | "pass"> | ||
| expect(summary.pass).toBe(true) | ||
| expect(summary.failures).toHaveLength(0) | ||
| expect(summary.confirmation).toEqual({ | ||
| initialFailureKeys: ["default:session-scroll-reading:interaction_ms_median"], | ||
| rawConfirmedFailures: ["default:session-scroll-reading:frame_gap_max_ms_delta"], | ||
| intersectedFailures: [], | ||
| }) | ||
| const comparison = JSON.parse(await readFile(outputPath, "utf8")) as PerfBaselineComparison | ||
| expect(comparison.pass).toBe(true) | ||
| expect(comparison.failures).toHaveLength(0) | ||
| expect(comparison.confirmation).toEqual({ | ||
| initialFailureKeys: ["default:session-scroll-reading:interaction_ms_median"], | ||
| rawConfirmedFailures: ["default:session-scroll-reading:frame_gap_max_ms_delta"], | ||
| intersectedFailures: [], | ||
| }) | ||
| }) | ||
|
|
||
| test("keeps top-level missing scenario failures in the confirmation scope", async () => { | ||
| const root = await mkdtemp(join(tmpdir(), "compare-perf-script-")) | ||
| tempRoots.push(root) | ||
| const basePath = join(root, "base.json") | ||
| const headPath = join(root, "head.json") | ||
| const initialPath = join(root, "perf-compare.json") | ||
| const outputPath = join(root, "perf-compare-confirm.json") | ||
| const initialComparison: PerfBaselineComparison = { | ||
| pass: false, | ||
| failures: ["missing_head_scenario:default:session-scroll-reading"], | ||
| warnings: [], | ||
| scenarios: [], | ||
| } | ||
|
|
||
| await writeJson(basePath, [scenario({ branch: "base" })]) | ||
| await writeJson(headPath, []) | ||
| await writeJson(initialPath, initialComparison) | ||
|
|
||
| const child = Bun.spawn( | ||
| [ | ||
| process.execPath, | ||
| "script/compare-perf.ts", | ||
| "--base", | ||
| basePath, | ||
| "--head", | ||
| headPath, | ||
| "--output", | ||
| outputPath, | ||
| "--failures-from", | ||
| initialPath, | ||
| ], | ||
| { | ||
| cwd: process.cwd(), | ||
| stderr: "pipe", | ||
| stdout: "pipe", | ||
| }, | ||
| ) | ||
| const [exitCode, stdout, stderr] = await Promise.all([ | ||
| child.exited, | ||
| new Response(child.stdout).text(), | ||
| new Response(child.stderr).text(), | ||
| ]) | ||
|
|
||
| expect(stderr).toBe("") | ||
| expect(exitCode).toBe(1) | ||
| const summary = JSON.parse(stdout) as Pick<PerfBaselineComparison, "failures" | "pass"> | ||
| expect(summary.pass).toBe(false) | ||
| expect(summary.failures).toEqual(["missing_head_scenario:default:session-scroll-reading"]) | ||
| const comparison = JSON.parse(await readFile(outputPath, "utf8")) as PerfBaselineComparison | ||
| expect(comparison.pass).toBe(false) | ||
| expect(comparison.failures).toEqual(["missing_head_scenario:default:session-scroll-reading"]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.