Skip to content

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.

fix(sdk): the last silent benchmarks, and the API drift they were hiding

esengine7ff928666fde
diff --git a/sdk/benchmarks/physics.bench.ts b/sdk/benchmarks/physics.bench.ts
index 411eb3046..de43b1e0a 100644
--- a/sdk/benchmarks/physics.bench.ts
+++ b/sdk/benchmarks/physics.bench.ts
@@ -1,35 +1,20 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, bench, beforeAll } from 'vitest';
-import path from 'path';
import { World } from '../src/ecs/world';
import { defineBuiltin } from '../src/ecs/component';
import type { CppRegistry, ESEngineModule } from '../src/wasm';
import type { PhysicsWasmModule } from '../src/physics/PhysicsModuleLoader';
import { syncDynamicTransforms } from '../src/physics/PhysicsSystem';
import type { Entity } from '../src/types';
-import { WASM_DIR as WASM_DIR_SHARED } from '../tests/helpers/loadWasm';
+import { loadWasmModule, loadSideModule } from '../tests/helpers/loadWasm';
let wasmModule: ESEngineModule;
let physicsMod: PhysicsWasmModule;
-// Same resolution the integration tests use: $ESENGINE_WASM_DIR, then the
-// in-repo build output, then the editor's copy. Hard-coding the last of
-// those is why these never found a wasm in CI.
-const WASM_DIR = WASM_DIR_SHARED;
-
beforeAll(async () => {
- const engineJs = path.join(WASM_DIR, 'esengine.js');
- const engineMod = await import(engineJs);
- wasmModule = await engineMod.default({
- locateFile(p: string) { return path.join(WASM_DIR, p); },
- });
-
- const physicsJs = path.join(WASM_DIR, 'physics.js');
- const physicsFn = await import(physicsJs);
- physicsMod = await physicsFn.default({
- locateFile(p: string) { return path.join(WASM_DIR, p); },
- }) as PhysicsWasmModule;
+ wasmModule = await loadWasmModule();
+ physicsMod = await loadSideModule<PhysicsWasmModule>('physics');
physicsMod._physics_init(0, -9.81, 1 / 30, 4, 30, 10, 3);
});
diff --git a/sdk/benchmarks/spine.bench.ts b/sdk/benchmarks/spine.bench.ts
index a37ff9fda..644a7cbff 100644
--- a/sdk/benchmarks/spine.bench.ts
+++ b/sdk/benchmarks/spine.bench.ts
@@ -7,14 +7,17 @@ import { wrapSpineModule } from '../src/spine/SpineModuleLoader';
import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';
import { SpineModuleController } from '../src/spine/SpineController';
import type { ESEngineModule } from '../src/wasm';
-import { WASM_DIR as WASM_DIR_SHARED } from '../tests/helpers/loadWasm';
+import { WASM_DIR, loadWasmModule } from '../tests/helpers/loadWasm';
-// Same resolution the integration tests use: $ESENGINE_WASM_DIR, then the
-// in-repo build output, then the editor's copy. Hard-coding the last of
-// those is why these never found a wasm in CI.
-const WASM_DIR = WASM_DIR_SHARED;
const SPINE_ASSETS = path.resolve(__dirname, 'fixtures/spine');
+/** One visitor for every extraction benchmark, so what they measure is the
+ * extraction and not the cost of allocating a closure per call. */
+const NOOP_BATCH = () => { /* visit and discard */ };
+
+/** Interleaved x,y,u,v,r,g,b,a — the layout every skeletal module writes. */
+const VERTEX_FLOATS = 8;
+
let raw: SpineWasmModule;
let api: SpineWrappedAPI;
let controller: SpineModuleController;
@@ -42,13 +45,7 @@ beforeAll(async () => {
api = wrapSpineModule(raw);
controller = new SpineModuleController(raw, api);
- const coreJsPath = path.join(WASM_DIR, 'esengine.js');
- const coreMod = await import(coreJsPath);
- coreModule = await coreMod.default({
- locateFile(p: string) {
- return path.join(WASM_DIR, p);
- },
- }) as ESEngineModule;
+ coreModule = await loadWasmModule();
spineboySkel = fs.readFileSync(path.join(SPINE_ASSETS, 'spineboy-38/spineboy-pro.skel'));
spineboyAtlas = fs.readFileSync(path.join(SPINE_ASSETS, 'spineboy-38/spineboy.atlas'), 'utf-8');
@@ -248,7 +245,7 @@ describe('Spine: mesh extraction - spineboy', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -258,7 +255,7 @@ describe('Spine: mesh extraction - spineboy', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -268,7 +265,7 @@ describe('Spine: mesh extraction - spineboy', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -278,7 +275,7 @@ describe('Spine: mesh extraction - spineboy', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -288,7 +285,7 @@ describe('Spine: mesh extraction - spineboy', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
});
@@ -302,7 +299,7 @@ describe('Spine: mesh extraction - raptor (complex)', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -312,7 +309,7 @@ describe('Spine: mesh extraction - raptor (complex)', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
@@ -322,7 +319,7 @@ describe('Spine: mesh extraction - raptor (complex)', () => {
controller.play(id, 'walk', true);
controller.update(id, DT);
}
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
cleanupInstances(skelHandle, instances);
});
});
@@ -340,7 +337,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -352,7 +349,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -364,7 +361,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -376,7 +373,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -388,7 +385,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -400,7 +397,7 @@ describe('Spine: full frame (update + extract) - spineboy', () => {
for (let frame = 0; frame < 60; frame++) {
for (const id of instances) {
controller.update(id, DT);
- controller.extractMeshBatches(id);
+ controller.forEachMeshBatch(id, NOOP_BATCH);
}
}
cleanupInstances(skelHandle, instances);
@@ -416,12 +413,11 @@ describe('Spine: vertex/batch statistics', () => {
const { skelHandle, instanceId } = loadAndSetup(spineboySkel, spineboyAtlas);
controller.play(instanceId, 'walk', true);
controller.update(instanceId, 1 / 60);
- const batches = controller.extractMeshBatches(instanceId);
let totalVerts = 0, totalIndices = 0;
- for (const b of batches) {
- totalVerts += b.vertices.length / 8;
- totalIndices += b.indices.length;
- }
+ controller.forEachMeshBatch(instanceId, (_v, _i, vertexCount, indexCount) => {
+ totalVerts += vertexCount;
+ totalIndices += indexCount;
+ });
controller.destroyInstance(instanceId);
controller.unloadSkeleton(skelHandle);
});
@@ -430,12 +426,11 @@ describe('Spine: vertex/batch statistics', () => {
const { skelHandle, instanceId } = loadAndSetup(raptorSkel, raptorAtlas);
controller.play(instanceId, 'walk', true);
controller.update(instanceId, 1 / 60);
- const batches = controller.extractMeshBatches(instanceId);
let totalVerts = 0, totalIndices = 0;
- for (const b of batches) {
- totalVerts += b.vertices.length / 8;
- totalIndices += b.indices.length;
- }
+ controller.forEachMeshBatch(instanceId, (_v, _i, vertexCount, indexCount) => {
+ totalVerts += vertexCount;
+ totalIndices += indexCount;
+ });
controller.destroyInstance(instanceId);
controller.unloadSkeleton(skelHandle);
});
@@ -444,12 +439,11 @@ describe('Spine: vertex/batch statistics', () => {
const { skelHandle, instanceId } = loadAndSetup(coinSkel, coinAtlas);
controller.play(instanceId, 'animation', true);
controller.update(instanceId, 1 / 60);
- const batches = controller.extractMeshBatches(instanceId);
let totalVerts = 0, totalIndices = 0;
- for (const b of batches) {
- totalVerts += b.vertices.length / 8;
- totalIndices += b.indices.length;
- }
+ controller.forEachMeshBatch(instanceId, (_v, _i, vertexCount, indexCount) => {
+ totalVerts += vertexCount;
+ totalIndices += indexCount;
+ });
controller.destroyInstance(instanceId);
controller.unloadSkeleton(skelHandle);
});
@@ -481,21 +475,24 @@ function prepareExtractedBatches(
}
const entries: CachedBatchEntry[] = [];
for (let i = 0; i < instances.length; i++) {
- const batches = controller.extractMeshBatches(instances[i]);
- for (const b of batches) {
- if (b.vertices.length === 0 || b.indices.length === 0) continue;
- entries.push({
- vertices: b.vertices,
- indices: b.indices,
- textureId: b.textureId,
- blendMode: b.blendMode,
- entity: i + 1,
- skeletonScale: 1,
- flipX: false,
- flipY: false,
- layer: 0,
+ controller.forEachMeshBatch(instances[i],
+ (vertBytes, indexBytes, vertexCount, indexCount, textureId, blendMode) => {
+ if (vertexCount === 0 || indexCount === 0) return;
+ // The visitor lends views into the module heap that are valid only
+ // for the duration of the call, so a cache that outlives it copies.
+ const vertices = new Float32Array(vertexCount * VERTEX_FLOATS);
+ new Uint8Array(vertices.buffer).set(vertBytes);
+ const indices = new Uint16Array(indexCount);
+ new Uint8Array(indices.buffer).set(indexBytes);
+ entries.push({
+ vertices, indices, textureId, blendMode,
+ entity: i + 1,
+ skeletonScale: 1,
+ flipX: false,
+ flipY: false,
+ layer: 0,
+ });
});
- }
}
return { skelHandle, instances, entries };
}
@@ -527,7 +524,8 @@ function simulateDataCopyOnly(entries: CachedBatchEntry[]) {
}
function simulateDataCopyAndSubmit(entries: CachedBatchEntry[]) {
- const submitFn = coreModule.renderer_submitSpineBatchByEntity;
+ // Renamed when the spine path was generalised to skeletal; same signature.
+ const submitFn = coreModule.renderer_submitSkeletalBatchByEntity;
const registry = new coreModule.Registry();
let totalVertBytes = 0;
@@ -669,7 +667,7 @@ describe('Engine overhead: proportion (Spine update vs engine copy+submit)', ()
controller.update(id, DT);
}
for (let frame = 0; frame < 60; frame++) {
- for (const id of instances) controller.extractMeshBatches(id);
+ for (const id of instances) controller.forEachMeshBatch(id, NOOP_BATCH);
}
cleanupInstances(skelHandle, instances);
});
diff --git a/sdk/benchmarks/wasm-vs-world.bench.ts b/sdk/benchmarks/wasm-vs-world.bench.ts
index 320d34782..d40a088e1 100644
--- a/sdk/benchmarks/wasm-vs-world.bench.ts
+++ b/sdk/benchmarks/wasm-vs-world.bench.ts
@@ -1,179 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, bench, beforeAll } from 'vitest';
-import path from 'path';
import { World } from '../src/ecs/world';
-import { defineBuiltin } from '../src/ecs/component';
+import { defineComponent, Transform, Sprite, Camera } from '../src/ecs/component';
+import { RigidBody, BoxCollider, CircleCollider } from '../src/physics/PhysicsComponents';
+import { convertForWasm } from '../src/ecs/bridge/BuiltinBridge';
import type { CppRegistry, ESEngineModule } from '../src/wasm';
-import { WASM_DIR as WASM_DIR_SHARED } from '../tests/helpers/loadWasm';
+import { loadWasmModule } from '../tests/helpers/loadWasm';
let wasmModule: ESEngineModule;
-// Same resolution the integration tests use: $ESENGINE_WASM_DIR, then the
-// in-repo build output, then the editor's copy. Hard-coding the last of
-// those is why these never found a wasm in CI.
-const WASM_DIR = WASM_DIR_SHARED;
-
beforeAll(async () => {
- const jsPath = path.join(WASM_DIR, 'esengine.js');
- const mod = await import(jsPath);
- wasmModule = await mod.default({
- locateFile(p: string) {
- return path.join(WASM_DIR, p);
- },
- });
+ wasmModule = await loadWasmModule();
});
-const Transform = defineBuiltin('Transform', {
- position: { x: 0, y: 0, z: 0 },
- rotation: { x: 0, y: 0, z: 0, w: 1 },
- scale: { x: 1, y: 1, z: 1 },
- worldPosition: { x: 0, y: 0, z: 0 },
- worldRotation: { x: 0, y: 0, z: 0, w: 1 },
- worldScale: { x: 1, y: 1, z: 1 },
-});
+// The embind payloads are built from the components' own defaults — the same
+// source BuiltinBridge inserts from. Hand-written copies of the C++ structs are
+// what these used to be, and they had drifted: Camera's four viewport scalars
+// became one Vec4 and every case touching it silently measured nothing.
+const wasmData = (def: { _default: unknown; colorKeys: readonly string[] }) =>
+ convertForWasm({ ...(def._default as Record<string, unknown>) }, def.colorKeys);
-const Sprite = defineBuiltin('Sprite', {
- texture: 0,
- color: { r: 1, g: 1, b: 1, a: 1 },
- size: { x: 100, y: 100 },
- uvOffset: { x: 0, y: 0 },
- uvScale: { x: 1, y: 1 },
- layer: 0,
- flipX: false,
- flipY: false,
- material: 0,
- enabled: true,
-});
+// The SDK-side shape (colors as r/g/b/a) is the component's default as authored;
+// the wasm one is that run through the same conversion the bridge uses.
+const sdkData = (def: { _default: unknown }) => ({ ...(def._default as Record<string, unknown>) });
-const Velocity = defineBuiltin('Velocity', {
+const SPRITE_SDK = sdkData(Sprite);
+const TRANSFORM_DATA = wasmData(Transform);
+const SPRITE_DATA = wasmData(Sprite);
+const CAMERA_DATA = wasmData(Camera);
+const RIGIDBODY_DATA = wasmData(RigidBody);
+const BOXCOLLIDER_DATA = wasmData(BoxCollider);
+const CIRCLECOLLIDER_DATA = wasmData(CircleCollider);
+
+const Velocity = defineComponent('BenchVelocity', {
linear: { x: 0, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 0 },
});
-const Camera = defineBuiltin('Camera', {
- projectionType: 0,
- fov: 60,
- orthoSize: 5,
- nearPlane: 0.1,
- farPlane: 1000,
- aspectRatio: 0,
- isActive: false,
- priority: 0,
- viewportX: 0,
- viewportY: 0,
- viewportW: 1,
- viewportH: 1,
- clearFlags: 3,
-});
-
-const UIRect = defineBuiltin('UIRect', {
- anchorMin: { x: 0.5, y: 0.5 },
- anchorMax: { x: 0.5, y: 0.5 },
- offsetMin: { x: 0, y: 0 },
- offsetMax: { x: 0, y: 0 },
- size: { x: 100, y: 100 },
- pivot: { x: 0.5, y: 0.5 },
-});
-
-const RigidBody = defineBuiltin('RigidBody', {
- bodyType: 2,
- gravityScale: 1,
- linearDamping: 0,
- angularDamping: 0,
- fixedRotation: false,
- bullet: false,
- enabled: true,
-});
-
-const BoxCollider = defineBuiltin('BoxCollider', {
- halfExtents: { x: 0.5, y: 0.5 },
- offset: { x: 0, y: 0 },
- density: 1,
- friction: 0.3,
- restitution: 0,
- isSensor: false,
- enabled: true,
- categoryBits: 0x0001,
- maskBits: 0xFFFF,
-});
-
-const CircleCollider = defineBuiltin('CircleCollider', {
- radius: 0.5,
- offset: { x: 0, y: 0 },
- density: 1,
- friction: 0.3,
- restitution: 0,
- isSensor: false,
- enabled: true,
- categoryBits: 0x0001,
- maskBits: 0xFFFF,
-});
-
const VELOCITY_DATA = {
linear: { x: 5, y: 0, z: 0 },
angular: { x: 0, y: 0, z: 1 },
};
-const CAMERA_DATA = {
- projectionType: 1,
- fov: 60,
- orthoSize: 5,
- nearPlane: 0.1,
- farPlane: 1000,
- aspectRatio: 1.777,
- isActive: true,
- priority: 0,
- viewportX: 0,
- viewportY: 0,
- viewportW: 1,
- viewportH: 1,
- clearFlags: 3,
-};
-
-const UIRECT_DATA = {
- anchorMin: { x: 0, y: 0 },
- anchorMax: { x: 1, y: 1 },
- offsetMin: { x: 10, y: 10 },
- offsetMax: { x: -10, y: -10 },
- size: { x: 200, y: 100 },
- pivot: { x: 0.5, y: 0.5 },
-};
-
-const RIGIDBODY_DATA = {
- bodyType: 2,
- gravityScale: 1,
- linearDamping: 0.1,
- angularDamping: 0.05,
- fixedRotation: false,
- bullet: false,
- enabled: true,
-};
-
-const BOXCOLLIDER_DATA = {
- halfExtents: { x: 0.5, y: 0.5 },
- offset: { x: 0, y: 0 },
- density: 1,
- friction: 0.3,
- restitution: 0.2,
- isSensor: false,
- enabled: true,
- categoryBits: 0x0001,
- maskBits: 0xFFFF,
-};
-
-const CIRCLECOLLIDER_DATA = {
- radius: 0.5,
- offset: { x: 0, y: 0 },
- density: 1,
- friction: 0.3,
- restitution: 0.2,
- isSensor: false,
- enabled: true,
- categoryBits: 0x0001,
- maskBits: 0xFFFF,
-};
-
const TRANSFORM_WASM = {
position: { x: 1, y: 2, z: 0 },
rotation: { x: 0, y: 0, z: 0, w: 1 },
@@ -183,32 +52,6 @@ const TRANSFORM_WASM = {
worldScale: { x: 1, y: 1, z: 1 },
};
-const SPRITE_SDK = {
- texture: 0,
- color: { r: 1, g: 1, b: 1, a: 1 },
- size: { x: 100, y: 100 },
- uvOffset: { x: 0, y: 0 },
- uvScale: { x: 1, y: 1 },
- layer: 0,
- flipX: false,
- flipY: false,
- material: 0,
- enabled: true,
-};
-
-const SPRITE_WASM = {
- texture: 0,
- color: { x: 1, y: 1, z: 1, w: 1 },
- size: { x: 100, y: 100 },
- uvOffset: { x: 0, y: 0 },
- uvScale: { x: 1, y: 1 },
- layer: 0,
- flipX: false,
- flipY: false,
- material: 0,
- enabled: true,
-};
-
describe('World wrapper vs direct WASM - spawn', () => {
bench('direct WASM: registry.create()', () => {
const reg = new wasmModule.Registry();
@@ -269,7 +112,7 @@ describe('World wrapper vs direct WASM - get (with color conversion)', () => {
bench('direct WASM: getSprite x100 (no conversion)', () => {
const reg = new wasmModule.Registry();
const e = reg.create();
- reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
for (let i = 0; i < 100; i++) reg.getSprite(e);
reg.delete();
});
@@ -371,7 +214,7 @@ describe('Ptr-based getter vs embind getter - Sprite', () => {
bench('embind: getSprite x100', () => {
const reg = new wasmModule.Registry();
const e = reg.create();
- reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
for (let i = 0; i < 100; i++) reg.getSprite(e);
reg.delete();
});
@@ -395,7 +238,7 @@ describe('Ptr-based multi-entity query - Transform + Sprite', () => {
for (let i = 0; i < 100; i++) {
const e = reg.create();
reg.addTransform(e, TRANSFORM_WASM);
- reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
entities.push(e);
}
for (const e of entities) {
@@ -468,27 +311,6 @@ describe('Ptr-based getter vs embind - Camera', () => {
});
});
-describe('Ptr-based getter vs embind - UIRect', () => {
- bench('embind: getUIRect x100', () => {
- const reg = new wasmModule.Registry();
- const e = reg.create();
- (reg as any).addUIRect(e, UIRECT_DATA);
- for (let i = 0; i < 100; i++) (reg as any).getUIRect(e);
- reg.delete();
- });
-
- bench('ptr-based: resolveGetter(UIRect) x100', () => {
- const world = new World();
- const reg = new wasmModule.Registry();
- world.connectCpp(reg as unknown as CppRegistry, wasmModule);
- const e = world.spawn();
- world.insert(e, UIRect, UIRECT_DATA as any);
- const getter = world.resolveGetter(UIRect)!;
- for (let i = 0; i < 100; i++) getter(e);
- reg.delete();
- });
-});
-
describe('Ptr-based getter vs embind - RigidBody', () => {
bench('embind: getRigidBody x100', () => {
const reg = new wasmModule.Registry();
@@ -581,8 +403,8 @@ describe('Ptr-based setter vs embind - Sprite write', () => {
bench('embind: addSprite (set) x100', () => {
const reg = new wasmModule.Registry();
const e = reg.create();
- reg.addSprite(e, SPRITE_WASM);
- for (let i = 0; i < 100; i++) reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
+ for (let i = 0; i < 100; i++) reg.addSprite(e, SPRITE_DATA);
reg.delete();
});
@@ -669,7 +491,7 @@ describe('Ptr-based has vs embind - Sprite', () => {
bench('embind: hasSprite x1000', () => {
const reg = new wasmModule.Registry();
const e = reg.create();
- reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
for (let i = 0; i < 1000; i++) reg.hasSprite(e);
reg.delete();
});
@@ -726,7 +548,7 @@ describe('World wrapper overhead - full entity lifecycle', () => {
for (let i = 0; i < 50; i++) {
const e = reg.create();
reg.addTransform(e, TRANSFORM_WASM);
- reg.addSprite(e, SPRITE_WASM);
+ reg.addSprite(e, SPRITE_DATA);
reg.getTransform(e);
reg.getSprite(e);
reg.destroy(e);
diff --git a/sdk/etc/perf.snapshot.json b/sdk/etc/perf.snapshot.json
index c75feacb7..2a8c3caa0 100644
--- a/sdk/etc/perf.snapshot.json
+++ b/sdk/etc/perf.snapshot.json
@@ -1,13 +1,13 @@
{
"note": "Generated by tools/perf-guard.mjs — run --update to accept changes.",
"tolerance": 0.3,
- "cases": 174,
+ "cases": 230,
"ratios": {
- "ui-layout: editing a field vs adding a node": 0.228,
+ "ui-layout: editing a field vs adding a node": 0.227,
"ui-layout: editing a field vs an idle frame": 10.9,
- "query: count vs iterating": 0.00613,
- "change-tracking: tracked vs untracked write-back": 1.02,
- "uiMath: reusing a result vs allocating one": 0.296,
- "system: three params vs none": 3.32
+ "query: count vs iterating": 0.00609,
+ "change-tracking: tracked vs untracked write-back": 1.05,
+ "uiMath: reusing a result vs allocating one": 0.288,
+ "system: three params vs none": 3.29
}
}
diff --git a/sdk/tests/helpers/loadWasm.ts b/sdk/tests/helpers/loadWasm.ts
index be6d65a76..769ef50dd 100644
--- a/sdk/tests/helpers/loadWasm.ts
+++ b/sdk/tests/helpers/loadWasm.ts
@@ -63,3 +63,22 @@ export async function loadWasmModule(): Promise<ESEngineModule> {
cachedModule = await factory({ wasmBinary }) as ESEngineModule;
return cachedModule;
}
+
+/**
+ * A side module (physics, spine38, …), loaded the same way: bytes handed
+ * straight to the factory.
+ *
+ * `locateFile` is the other way emscripten glue finds its binary, and it is the
+ * wrong one here — under the happy-dom test environment the glue takes itself
+ * for a browser and fetches the path, which resolves against localhost and is
+ * refused. The physics benchmarks measured nothing for exactly that reason.
+ */
+export async function loadSideModule<T>(name: string): Promise<T> {
+ const wasmBinary = readFileSync(resolve(WASM_DIR, `${name}.wasm`));
+ const factory = (await import(resolve(WASM_DIR, `${name}.js`))).default;
+ return await factory({ wasmBinary }) as T;
+}
+
+/** Whether a side module was built alongside the engine. */
+export const hasSideModule = (name: string): boolean =>
+ existsSync(resolve(WASM_DIR, `${name}.wasm`));