Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ui/bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ walltime for elapsed time, including async frame output, then runs the benchmark
again with memory tracking to report allocations and peak memory.

`createUI()` and fixture construction are outside the timed
sample. The initial-render comparison measures starting `ui.main()` through the first
sample, and each `beforeEach` forces a garbage collection afterwards so setup
garbage is not collected during a timed sample. The initial-render comparison measures starting `ui.main()` through the first
frame's output callback, after the terminal setup write. Each update workload compares
six tree shapes at 100, 500, 1,000, and 1,500 component elements:

Expand Down
8 changes: 8 additions & 0 deletions packages/ui/bench/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export async function waitFor(predicate: () => boolean): Promise<void> {
}
}

/**
* Collect fixture setup garbage before a timed sample so its GC pause is not
* charged to the sample. Requires `--expose-gc`, which the bench project sets.
*/
export function collectGarbage(): void {
globalThis.gc?.();
}

// see the readme for explanation of tree shapes
export const shapes = ['grass', 'bamboo', 'bush', 'evergreen', 'maple', 'sequoia'] as const;
export type TreeShape = (typeof shapes)[number];
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/bench/render.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test } from 'vitest';
import {
applyWorkload,
collectGarbage,
setupUI,
shapes,
waitFor,
Expand Down Expand Up @@ -29,6 +30,7 @@ test('initial render', { timeout: 300_000 }, async ({ bench }) => {
{
async beforeEach() {
fixture = await setupUI(benchmarkCase.nodeCount, benchmarkCase.shape);
collectGarbage();
},
async afterEach() {
await fixture.close();
Expand All @@ -52,6 +54,7 @@ test.for(workloads)('%s', { timeout: 300_000 }, async (workload, { bench }) => {
fixture = await setupUI(benchmarkCase.nodeCount, benchmarkCase.shape);
await fixture.start();
iteration = 0;
collectGarbage();
},
async afterEach() {
await fixture.close();
Expand Down
2 changes: 2 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default defineConfig({
name: 'bench',
benchmark: { enabled: true, include: ['**/*.bench.ts'] },
experimental: { viteModuleRunner: false },
// lets beforeEach hooks collect setup garbage outside timed samples
execArgv: ['--expose-gc'],
},
},
],
Expand Down
Loading