fix(scale): 초기 JS 기록 대조의 합계 허용 오차를 256 B로 둔다

문제: initialJavascriptRecordDrift가 합계를 1%까지 같다고 본다.
202,927 B에서 1%는 2,029 B로, 남은 여유 1,873 B와 기능 하나(768 B)보다
크다. 템플릿 변경이 여유를 다 써도 기록을 다시 쓰지 않은 채 test:unit을
통과하고, 기록을 인용한 문서는 없는 여유를 말한다. 단위 테스트는 1,500 B
차이를 "같음"으로 고정했다.

고른 방법: 합계만 바이트 상한 256 B(INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES)로
바꾼다. build id 차이(기록된 실행 사이 6 B, 48 B)는 넘고 기능 하나보다는
작다. 기능·context 비용(10%)과 파일 수(정확)는 그대로다. 단위 테스트는
48 B·200 B 차이는 통과, 300 B 증가와 1,500 B 차이는 실패로 고정한다.
performance-evidence.md의 "합계 1% 초과" 문장을 고쳤다.
버린 대안: 여유 자체를 기록해 대조 — 예산이 바뀔 때마다 같이 바뀌어
더 쉽게 낡는다.

위험·한계: 초기 JS를 수백 바이트 움직이는 템플릿 변경마다 기록을 다시
써야 한다(의도). CI와 로컬의 build id 차이가 256 B를 넘는 일이 생기면
test:unit이 흔들린다. 지금까지 본 차이는 50 B 안이다. 이 커밋은 기록
숫자를 바꾸지 않는다. 현재 기록과 빌드의 차이는 0 B였다(리뷰 15-lab).

검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/feature-shape-growth.test.ts

Refs: 1105/15-02
This commit is contained in:
DongHyeonka
2026-11-06 01:23:48 +09:00
parent c9aa73fbfd
commit 46359a1c79
3 changed files with 45 additions and 14 deletions
+21 -11
View File
@@ -216,24 +216,34 @@ export async function measureInitialJavascriptCosts(): Promise<InitialJavascript
}
/**
* Fields of the record that no longer describe the build. The total moves
* by tens of bytes with the build id (CI and local builds differ), so it may
* be 1% off; the per-feature and per-context costs are differences of builds
* with the same id but only a few hundred bytes, so 10%; the file count is
* exact.
* 1105/15-02. How far the total may be from the record, in gzip bytes. The
* total moves by tens of bytes with the build id (CI and local builds
* differ: 6 B and 48 B between recorded runs), so it cannot be exact. It
* used to be 1% of the total, 2,029 B, which is more than the room left
* under the budget (1,873 B at 8a44226) and more than one feature (768 B):
* the record and the documents that cite it could claim room that was
* gone. 256 B is above the build id spread and below one feature.
*/
export const INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES = 256;
/**
* Fields of the record that no longer describe the build. The total may be
* INITIAL_JAVASCRIPT_RECORD_TOLERANCE_BYTES off; the per-feature and
* per-context costs are differences of builds with the same id but only a
* few hundred bytes, so 10%; the file count is exact.
*/
export function initialJavascriptRecordDrift(
measured: InitialJavascriptCosts,
record: InitialJavascriptCosts,
): string[] {
const tolerance: Readonly<Record<keyof InitialJavascriptCosts, number>> = {
gzipBytes: 0.01,
const allowed: Readonly<Record<keyof InitialJavascriptCosts, number>> = {
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]}`);
}