A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(size): the report says what the export's own packing bought
esengineb0a1b560cec3
diff --git a/desktop b/desktopindex 8e5a659ce..77c125f33 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 8e5a659ce0c2be46b1859e7513193320a3f65598+Subproject commit 77c125f3342f7cfa9be0bba4ef429685b9ebe4e9diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex 653332236..d5397b8e3 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -241,6 +241,9 @@ export interface ExportGameResult {/** @internal Subpackage roots the export staged, for the size report to keep* off the main package's cap. Consumed here and dropped. */subPackageRoots?: string[];+ /** @internal Staged path → what it weighed before the export packed it.+ * Consumed by the size report and dropped. */+ packedFrom?: Record<string, number>;warnings: string[];errors: string[];/** Android: the generated Gradle project, for the editor to reveal. Absent@@ -560,6 +563,7 @@ async function attachSizeReport(result: ExportGameResult, opts: ExportGameOptionsubPackageRoots: result.subPackageRoots,inlineOf: result.inlineParts ? { file: 'index.html', parts: result.inlineParts } : undefined,inclusion: result.inclusion,+ packedFrom: result.packedFrom,// The project, not the build: what this target weighed last time lives with// the project, and the settings ride along so a compression change is not// read as content that grew.diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.tsindex c54c5cb09..2aa05ddf1 100644--- a/pipeline/src/export/exportMiniGame.ts+++ b/pipeline/src/export/exportMiniGame.ts@@ -72,6 +72,9 @@ export interface ExportMiniGameResult {bundleModules?: ModuleBytes[];/** Project-relative subpackage roots — what is NOT on the main package's cap. */subPackageRoots?: string[];+ /** Staged path → what that file weighed before this export packed it. A limit+ * is judged on packed bytes, so the report has no other way to know. */+ packedFrom?: Record<string, number>;}interface CookManifest {@@ -609,6 +612,8 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {// fails real-device compile ("invalid file: wasm/basis.js … Unexpected token .").// Scoped to wasm/ (exporter-owned); the outDir root also hosts devtools'// project.private.config.json, so we don't wipe the whole tree.+ /** Filled by the brotli branch below; the report has no other way to know. */+ const packedFrom: Record<string, number> = {};progress({ phase: 'Copying runtime' });const wasmOut = path.join(absOut, 'wasm');await rm(wasmOut, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });@@ -640,6 +645,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {},});await writeFile(dest, packed);+ packedFrom[f.staged.split(path.sep).join('/')] = raw.byteLength;progress({phase: 'Copying runtime',detail: `${f.staged} ${(raw.byteLength / 1048576).toFixed(2)}MB → ${(packed.byteLength / 1048576).toFixed(2)}MB`,@@ -661,5 +667,6 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {// NOT on, and it cannot tell a subpackage root from any other directory. The// export that made them names them.subPackageRoots: subPackages.subPackages.map((sp) => sp.root),+ ...(Object.keys(packedFrom).length > 0 ? { packedFrom } : {}),};}diff --git a/pipeline/src/export/sizeReport.ts b/pipeline/src/export/sizeReport.tsindex 89e11c9dc..164df2dad 100644--- a/pipeline/src/export/sizeReport.ts+++ b/pipeline/src/export/sizeReport.ts@@ -67,6 +67,9 @@ export interface BuildSizeEntry {kind: SizeKind;/** Absent for a file the cook did not stage (the engine runtime, the host page). */why?: SizeAttribution;+ /** What it weighed before the export packed it. Only set for a file the export+ * compressed itself — `bytes` is always what ships. */+ sourceBytes?: number;}export interface KindTotal {@@ -103,6 +106,10 @@ export interface BuildSizeReport {verdicts: SizeVerdict[];/** This build against the last one of the same platform; absent for the first. */since?: SizeComparison;+ /** What the export's own compression bought, when it compressed anything. A+ * limit is judged on packed bytes, so `bytes` everywhere else is the packed+ * number and this is the only place the other one appears. */+ packing?: { fromBytes: number; toBytes: number; fileCount: number };}/** How many files the report names individually. Enough to find the offender,@@ -239,6 +246,8 @@ export function entriesOf(buckets?: Map<string, SizeBucket>;logical?: Map<string, string>;inclusion?: Record<string, Inclusion>;+ /** Project-relative staged path → what it weighed before being packed. */+ packedFrom?: Readonly<Record<string, number>>;} = {},): BuildSizeEntry[] {const buckets = opts.buckets ?? new Map<string, SizeBucket>();@@ -249,7 +258,11 @@ export function entriesOf(const bucket = buckets.get(rel) ?? 'initial';const logical = opts.logical?.get(rel);const why = logical && opts.inclusion ? inclusionChain(logical, opts.inclusion) : undefined;- entries.push({ path: rel, bytes: file.bytes, bucket, kind: kindOf(rel), ...(why ? { why } : {}) });+ const from = opts.packedFrom?.[rel];+ entries.push({+ path: rel, bytes: file.bytes, bucket, kind: kindOf(rel),+ ...(why ? { why } : {}), ...(from !== undefined ? { sourceBytes: from } : {}),+ });}return entries;}@@ -314,6 +327,16 @@ export function summarizeEntries(report.deliverableBytes = opts.deliverableBytes;if (opts.deliverableName) report.deliverableName = opts.deliverableName;}+ // Summed from the entries rather than passed in: a file the export packed and+ // then did not ship must not be counted as a saving.+ const packed = entries.filter((e) => e.sourceBytes !== undefined);+ if (packed.length > 0) {+ report.packing = {+ fromBytes: packed.reduce((n, e) => n + (e.sourceBytes ?? 0), 0),+ toBytes: packed.reduce((n, e) => n + e.bytes, 0),+ fileCount: packed.length,+ };+ }report.verdicts = judge(report, opts.budgets ?? []);return report;}@@ -422,6 +445,12 @@ export async function measureBuild(opts: {* and a shipped package must not carry it.*/history?: { projectRoot: string; settings: SizeSettings };+ /**+ * Project-relative staged path → what that file weighed before this export+ * packed it. Only the export knows both numbers, and the report is the only+ * place anyone looks for them afterwards.+ */+ packedFrom?: Readonly<Record<string, number>>;}): Promise<BuildSizeReport> {const excluded: string[] = [];for (const file of opts.packages ?? []) {@@ -469,6 +498,7 @@ export async function measureBuild(opts: {buckets,logical: logicalIndexFrom(manifest),inclusion: opts.inclusion,+ packedFrom: opts.packedFrom,});const report = summarizeEntries(entries, {budgets: resolveSizeBudgets(opts.platform, {diff --git a/pipeline/tests/size-report.test.ts b/pipeline/tests/size-report.test.tsindex 15670c3b1..554847a26 100644--- a/pipeline/tests/size-report.test.ts+++ b/pipeline/tests/size-report.test.ts@@ -430,3 +430,40 @@ describe('this build against the last one', () => {}});});++/**+ * A WeChat limit is judged on PACKED bytes, so every figure the report carries+ * is the packed one and a reader has no way to see what the packing bought.+ * The export is the only place both numbers exist.+ */+describe('what the export packed', () => {+ const packed = (over: Partial<Record<string, number>> = {}) => entriesOf(+ [+ { path: 'wasm/esengine.wasm.br', bytes: 363617 },+ { path: 'game-bundle.js', bytes: 1064880 },+ ],+ { packedFrom: { 'wasm/esengine.wasm.br': 1828959, ...over } },+ );++ it('rides the entry it belongs to, and only that one', () => {+ const e = packed();+ expect(e.find((x) => x.path === 'wasm/esengine.wasm.br')?.sourceBytes).toBe(1828959);+ expect(e.find((x) => x.path === 'game-bundle.js')).not.toHaveProperty('sourceBytes');+ });++ it('is summed into one figure a reader can act on', () => {+ expect(summarizeEntries(packed()).packing)+ .toEqual({ fromBytes: 1828959, toBytes: 363617, fileCount: 1 });+ });++ // `bytes` stays what ships: a budget judged against the pre-packed number+ // would fail a package that fits.+ it('never changes what the package is judged to weigh', () => {+ expect(summarizeEntries(packed()).packageBytes).toBe(363617 + 1064880);+ });++ it('is absent when the export packed nothing, rather than zero', () => {+ expect(summarizeEntries(entriesOf([{ path: 'game-bundle.js', bytes: 10 }])).packing)+ .toBeUndefined();+ });+});