diff --git a/docs/operations/performance-evidence.md b/docs/operations/performance-evidence.md index 36608b1b..16394c4e 100644 --- a/docs/operations/performance-evidence.md +++ b/docs/operations/performance-evidence.md @@ -30,8 +30,11 @@ config/scale/feature-shape-ceilings.json의 `initialJavascript` 한 곳이다. | `perContextGzipBytes` | 새 context를 하나 더할 때 느는 초기 JS. 상한 512 B | - tests/unit/feature-shape-growth.test.ts(unit, merge 단계)가 매번 빌드해 이 - 값을 재고, 상한을 넘거나 기록과 다르면(합계 1% 초과, 파일 수 불일치, 기능· + 값을 재고, 상한을 넘거나 기록과 다르면(합계 256 B 초과, 파일 수 불일치, 기능· context 비용 10% 초과) 실패한다. 실패 메시지에 잰 값이 나온다. + - 합계의 허용 오차는 바이트로 둔다(1105/15-02). build id만 달라도 합계가 + 수십 B 움직이므로 0으로 둘 수 없다. 예전 1%(약 2 KB)는 남은 여유와 기능 + 하나보다 커서, 여유를 다 쓴 변경이 기록을 고치지 않고 지나갈 수 있었다. - 기록을 고칠 때는 `node scripts/scale/measure-feature-shape-growth.ts --initial-baseline --write`를 돌리고 같은 변경에 넣는다. - 여유는 예산에서 `gzipBytes`를 뺀 값이다. 그것을 `perFeatureGzipBytes`로 나누면 diff --git a/scripts/scale/measure-feature-shape-growth.ts b/scripts/scale/measure-feature-shape-growth.ts index a90ac987..0fb5b724 100644 --- a/scripts/scale/measure-feature-shape-growth.ts +++ b/scripts/scale/measure-feature-shape-growth.ts @@ -216,24 +216,34 @@ export async function measureInitialJavascriptCosts(): Promise> = { - gzipBytes: 0.01, + const allowed: Readonly> = { + gzipBytes: INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES, files: 0, - perFeatureGzipBytes: 0.1, - perContextGzipBytes: 0.1, + perFeatureGzipBytes: Math.abs(measured.perFeatureGzipBytes) * 0.1, + perContextGzipBytes: Math.abs(measured.perContextGzipBytes) * 0.1, }; - return (Object.keys(tolerance) as (keyof InitialJavascriptCosts)[]) - .filter((field) => Math.abs(record[field] - measured[field]) > Math.abs(measured[field]) * tolerance[field]) + return (Object.keys(allowed) as (keyof InitialJavascriptCosts)[]) + .filter((field) => Math.abs(record[field] - measured[field]) > allowed[field]) .map((field) => `${field}: record ${record[field]}, build ${measured[field]}`); } diff --git a/tests/unit/feature-shape-growth.test.ts b/tests/unit/feature-shape-growth.test.ts index fb267f0c..22ad957f 100644 --- a/tests/unit/feature-shape-growth.test.ts +++ b/tests/unit/feature-shape-growth.test.ts @@ -165,7 +165,14 @@ describe("feature-shape growth measurement (11-04)", () => { ).toEqual([]); }, 180_000); - it("reports a record more than 1% off the build, or a different file count", () => { + /** + * 1105/15-02. The total used to match within 1% (2,029 B at 202,927 B), + * more than the room left under the budget (1,873 B) and more than one + * feature (768 B), so a template change that took the room could leave the + * record. Now a few hundred bytes are enough to fail: above the build id + * spread (tens of bytes), below one feature. + */ + it("reports a record a few hundred bytes off the build, or a different file count", () => { const measured = { gzipBytes: 200_000, files: 25, @@ -173,9 +180,20 @@ describe("feature-shape growth measurement (11-04)", () => { perContextGzipBytes: 250, }; expect(initialJavascriptRecordDrift(measured, measured)).toEqual([]); + // The build id alone moves the total by tens of bytes. + expect( + initialJavascriptRecordDrift(measured, { ...measured, gzipBytes: 200_048 }), + ).toEqual([]); + expect( + initialJavascriptRecordDrift(measured, { ...measured, gzipBytes: 199_800 }), + ).toEqual([]); + // A template change that grows the initial JavaScript by 300 B. + expect( + initialJavascriptRecordDrift({ ...measured, gzipBytes: 200_300 }, measured), + ).toEqual(["gzipBytes: record 200000, build 200300"]); expect( initialJavascriptRecordDrift(measured, { ...measured, gzipBytes: 201_500 }), - ).toEqual([]); + ).toEqual(["gzipBytes: record 201500, build 200000"]); expect( initialJavascriptRecordDrift(measured, { ...measured, gzipBytes: 204_000 }), ).toEqual(["gzipBytes: record 204000, build 200000"]);