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:
@@ -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`로 나누면
|
||||
|
||||
@@ -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]}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
Reference in New Issue
Block a user