packages/testing/performance/README.md
Microbenchmarks for measuring and tracking performance of critical code paths.
Good fit:
Not a good fit:
Rule of thumb: If it runs millions of times per day across all users, benchmark it.
pnpm --filter=@n8n/performance bench # Run benchmarks
pnpm --filter=@n8n/performance bench:baseline # Save baseline for local comparison
pnpm --filter=@n8n/performance bench:compare # Compare against baseline (>10% = fail)
Benchmarks run automatically on PRs that touch packages/testing/performance/** or packages/workflow/src/**. CodSpeed counts CPU instructions instead of wall-clock time, producing deterministic results regardless of runner load. It comments on PRs with results and regression warnings.
You can also trigger benchmarks manually for any branch via Actions > Test: Benchmarks > Run workflow.
Local (bench) | CI | |
|---|---|---|
| Measurement | Wall-clock time (Hz, ms) | CPU instruction count |
| Noise | 15-30% variance | Near-zero variance |
| Best for | Quick sanity checks, comparing approaches | Automated regression detection |
Local benchmarks are useful for eyeballing performance during development. Use bench:baseline + bench:compare for before/after comparisons on the same machine in the same session.
// benchmarks/my-feature/thing.bench.ts
import { bench, describe } from 'vitest';
// Setup runs once, not measured
const data = createTestData();
describe('My Feature', () => {
bench('operation name', () => {
doTheThing(data);
});
});
name hz min max mean p99 rme samples
my operation 20,000 0.04 0.20 0.05 0.10 ±0.5% 10000
| Column | Meaning |
|---|---|
| hz | Operations per second (higher = faster) |
| mean | Average time per operation in ms |
| p99 | 99th percentile - worst case latency |
| rme | Margin of error - lower = more reliable |
| samples | Number of iterations run |
| Area | What it measures | Why it matters |
|---|---|---|
| Expression Engine | ={{ }} evaluation speed | Runs for every node parameter |
This package pins vitest@^3.2.0 independently from the monorepo catalog (^3.1.3) because CodSpeed requires vitest 3.2+.