Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions builder/wasm/wasm_size_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Gate each production wasm bridge on raw WASM and gzipped WASM plus glue.

The test-device variant is measured but does not ship. Raising a cap needs a reason in the PR.
The ground-plan budget is the bridge with the faces, the records, the near mesh, the outline slopes and line water.
The ground-plan budget is its recorded CI size plus the owner's margin; both parts print.
"""

from __future__ import annotations
Expand All @@ -16,18 +16,31 @@
from pathlib import Path


# Preserve the sum of the conversion, assembly and preview caps. Consolidation does not
# increase the permitted production download or raw WASM size.
# Measured in CI on the build with the outline's turns, the levels that the tiles carry, the faces' tile-line
# vertices, the decks' ceilings and end faces, the shared water level and curve of the feature bake, line water
# and its culverts with their mouths, the classifier's ford rule, and the storeys over the ground with their open
# junction ends, their ends on the stubs' points, what each deck is made of and the junctions that lie on the
# ground (the crate's feature `storeys` on, stable 1.100.0).
# The owner allows about 60 kB of code growth for the crossing block, stated in its pull request and recorded here.
GROUND_PLAN_MEASURED = {"gzipped": 806_847, "raw_wasm": 2_087_262}
# The owner's margin: compiler and dependency updates move the size by a few kilobytes and must not fail
# unrelated pull requests; real growth past the margin still fails. Raw gets the same fraction as gzipped.
# A pull request that changes the bridge's code records its own CI size here; the margin is only for toolchain
# and dependency noise.
GROUND_PLAN_MARGIN_GZIPPED = 8 * 1024
GROUND_PLAN_MARGIN = {
"gzipped": GROUND_PLAN_MARGIN_GZIPPED,
"raw_wasm": round(GROUND_PLAN_MARGIN_GZIPPED * GROUND_PLAN_MEASURED["raw_wasm"] / GROUND_PLAN_MEASURED["gzipped"]),
}

BUDGETS = {
# Preserve the sum of the conversion, assembly and preview caps. Consolidation does not
# increase the permitted production download or raw WASM size.
"builder": {"gzipped": (62 + 352 + 128) * 1024, "raw_wasm": (112 + 944 + 272) * 1024},
# Measured in CI on the build with the outline's turns, the levels that the tiles carry, the faces' tile-line
# vertices, the decks' ceilings and end faces, the shared water level and curve of the feature bake, line water
# and its culverts with their mouths, the classifier's ford rule, and the storeys over the ground with their open
# junction ends, their ends on the stubs' points, what each deck is made of and the junctions that lie on the
# ground (the crate's feature `storeys` on: 806,847 B gzipped with the glue, 2,087,262 B raw, stable 1.100.0), the
# next whole KiB. The owner allows a few per cent for line water and about 60 kB for the crossing block when stated.
"ground-plan": {"gzipped": 788 * 1024, "raw_wasm": 2039 * 1024},
"ground-plan": {key: GROUND_PLAN_MEASURED[key] + GROUND_PLAN_MARGIN[key] for key in GROUND_PLAN_MEASURED},
}
# A budget made of a measured size and a margin prints both, so a reviewer sees growth inside the margin.
BUDGET_PARTS = {"ground-plan": (GROUND_PLAN_MEASURED, GROUND_PLAN_MARGIN)}

ADVICE = {
"builder": (
Expand Down Expand Up @@ -101,13 +114,21 @@ def main() -> int:

failed = False
budgets = BUDGETS[args.module]
for label, measured, budget in (
("gzipped wasm + glue", total_gzipped, budgets["gzipped"]),
("raw wasm", raw_wasm, budgets["raw_wasm"]),
parts = BUDGET_PARTS.get(args.module)
for key, label, measured in (
("gzipped", "gzipped wasm + glue", total_gzipped),
("raw_wasm", "raw wasm", raw_wasm),
):
budget = budgets[key]
pct = 100 * measured / budget
status = "over" if measured > budget else "ok"
print(f"{label}: {measured:,} B / {budget:,} B budget ({pct:.0f}%) — {status}")
if parts:
recorded, margin = parts
print(
f" budget = {recorded[key]:,} B recorded + {margin[key]:,} B margin;"
f" {measured - recorded[key]:+,} B against the recorded size"
)
if measured > budget:
print(
f"::error::obc-{args.module}-bridge {label} is {measured:,} B, over the {budget:,} B budget."
Expand Down
Loading