Skip to content

Commit df7b7d7

Browse files
committed
fix: exclude brotli from budget-raise isolation gate
Brotli is not monotonic in code size—removing code can increase brotli (documented in minimal-gates.mjs, e.g. #1634 by up to 120 B). When --write-budgets ratchets down after a shrink that increases brotli, the new brotli ceiling (measured + 256) exceeds the previous ceiling, causing findBudgetRaises to report a raise. Since the PR also touches source files, checkBudgetRaises fails the isolation gate, blocking the intended ratchet-down workflow. Skip brotli keys in findBudgetRaises so only raw and gzip—the actual growth gate—can trigger the isolation check.
1 parent 6c52af2 commit df7b7d7

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const BUDGET_FILES = [
2020
];
2121
const PROSE = /\.mdx?$/;
2222

23-
// Every numeric leaf that exists on both sides and grew, as `file: a.b.c`.
23+
// Every non-brotli numeric leaf that exists on both sides and grew, as
24+
// `file: a.b.c`. Brotli is excluded because it is not monotonic in code size
25+
// (removing code can raise brotli), so it is not part of the growth gate.
2426
export function findBudgetRaises(file, before, after) {
2527
const raises = [];
2628
const walk = (left, right, trail) => {
@@ -31,7 +33,10 @@ export function findBudgetRaises(file, before, after) {
3133
return;
3234
}
3335
if (right && typeof right === 'object' && left && typeof left === 'object') {
34-
for (const key of Object.keys(right)) walk(left[key], right[key], [...trail, key]);
36+
for (const key of Object.keys(right)) {
37+
if (key === 'brotli') continue;
38+
walk(left[key], right[key], [...trail, key]);
39+
}
3540
}
3641
};
3742
walk(before, after, []);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 growth is excluded from raises because it is not monotonic', () => {
26+
const before = { context: { raw: 100, gzip: 50, brotli: 40 } };
27+
const after = { context: { raw: 100, gzip: 50, brotli: 296 } };
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)