Skip to content

Commit d3170d3

Browse files
committed
fix(bench): exclude brotli from budget-raise isolation gate
Brotli compression is non-monotonic: a strict code removal can raise brotli on some rows. The isolation check (budget-raises.mjs) was walking every numeric leaf including brotli, so any brotli increase alongside non-budget file changes would fail the 'raises land alone' CI step. This contradicts the design intent ('gate growth on raw and gzip') and would also fail future PRs that run --write-budgets when brotli ticks up naturally. Gate only raw and gzip leaves in findBudgetRaises. Brotli budgets are still enforced at their 256-byte headroom by the build step; they just no longer trigger the isolation rule.
1 parent 92814df commit d3170d3

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎benchmarks/bundle-size/budget-raises.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ export const BUDGET_FILES = [
2020
];
2121
const PROSE = /\.mdx?$/;
2222

23+
// Brotli is non-monotonic in code size (a strict removal can raise brotli on
24+
// some rows), so only raw and gzip growth triggers the isolation rule.
25+
const GATED_FORMATS = new Set(['raw', 'gzip']);
26+
2327
// Every numeric leaf that exists on both sides and grew, as `file: a.b.c`.
28+
// Only leaves whose immediate key is in GATED_FORMATS count as raises.
2429
export function findBudgetRaises(file, before, after) {
2530
const raises = [];
2631
const walk = (left, right, trail) => {
2732
if (typeof right === 'number') {
28-
if (typeof left === 'number' && right > left) {
33+
if (typeof left === 'number' && right > left && GATED_FORMATS.has(trail[trail.length - 1])) {
2934
raises.push({ budget: `${file}: ${trail.join('.')}`, before: left, after: right });
3035
}
3136
return;

‎benchmarks/bundle-size/budget-raises.test.mjs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { checkBudgetRaises, findBudgetRaises } from './budget-raises.mjs';
55
const MINIMAL = 'benchmarks/bundle-size/minimal-budgets.json';
66
const APP = 'benchmarks/bundle-size/app-budgets.json';
77

8-
test('only grown values that exist on both sides are raises', () => {
8+
test('only grown raw and gzip values that exist on both sides are raises', () => {
99
const before = {
1010
context: { raw: 100, gzip: 50, brotli: 40 },
1111
rows: { app: { gzip: 10 }, total: { gzip: 20 } },
1212
};
1313
const after = {
14-
context: { raw: 90, gzip: 51, brotli: 40 },
14+
context: { raw: 90, gzip: 51, brotli: 45 },
1515
rows: { app: { gzip: 10 }, total: { gzip: 21 } },
1616
added: { raw: 999, gzip: 999, brotli: 999 },
1717
};
@@ -22,6 +22,12 @@ test('only grown values that exist on both sides are raises', () => {
2222
assert.deepEqual(findBudgetRaises(MINIMAL, null, after), []);
2323
});
2424

25+
test('brotli raises are excluded because brotli is non-monotonic', () => {
26+
const before = { context: { raw: 100, gzip: 50, brotli: 40 } };
27+
const after = { context: { raw: 100, gzip: 50, brotli: 60 } };
28+
assert.deepEqual(findBudgetRaises(MINIMAL, before, after), []);
29+
});
30+
2531
test('a raise alone, with prose, is allowed', () => {
2632
const raises = [{ budget: `${MINIMAL}: context.gzip`, before: 50, after: 51 }];
2733
assert.deepEqual(

0 commit comments

Comments
 (0)