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.

test: add Spine performance benchmark

esengine42ad283290e4
diff --git a/sdk/benchmarks/fixtures/spine/coin-38/coin-pro.skel b/sdk/benchmarks/fixtures/spine/coin-38/coin-pro.skel
new file mode 100644
index 000000000..ef39592b6
Binary files /dev/null and b/sdk/benchmarks/fixtures/spine/coin-38/coin-pro.skel differ
diff --git a/sdk/benchmarks/fixtures/spine/coin-38/coin.atlas b/sdk/benchmarks/fixtures/spine/coin-38/coin.atlas
new file mode 100644
index 000000000..3b6884311
--- /dev/null
+++ b/sdk/benchmarks/fixtures/spine/coin-38/coin.atlas
@@ -0,0 +1,55 @@
+
+coin.png
+size: 1024,1024
+format: RGBA8888
+filter: Linear,Linear
+repeat: none
+coin-front-logo
+ rotate: false
+ xy: 2, 609
+ size: 305, 302
+ orig: 305, 302
+ offset: 0, 0
+ index: -1
+coin-front-shine-logo
+ rotate: false
+ xy: 309, 629
+ size: 282, 282
+ orig: 282, 282
+ offset: 0, 0
+ index: -1
+coin-front-shine-spineboy
+ rotate: false
+ xy: 2, 21
+ size: 282, 282
+ orig: 282, 282
+ offset: 0, 0
+ index: -1
+coin-front-spineboy
+ rotate: false
+ xy: 2, 305
+ size: 305, 302
+ orig: 305, 302
+ offset: 0, 0
+ index: -1
+coin-side-round
+ rotate: false
+ xy: 309, 345
+ size: 144, 282
+ orig: 144, 282
+ offset: 0, 0
+ index: -1
+coin-side-straight
+ rotate: true
+ xy: 2, 2
+ size: 17, 282
+ orig: 17, 282
+ offset: 0, 0
+ index: -1
+shine
+ rotate: false
+ xy: 593, 666
+ size: 72, 245
+ orig: 72, 245
+ offset: 0, 0
+ index: -1
diff --git a/sdk/benchmarks/fixtures/spine/raptor-38/raptor-pro.skel b/sdk/benchmarks/fixtures/spine/raptor-38/raptor-pro.skel
new file mode 100644
index 000000000..77d9da9ee
Binary files /dev/null and b/sdk/benchmarks/fixtures/spine/raptor-38/raptor-pro.skel differ
diff --git a/sdk/benchmarks/fixtures/spine/raptor-38/raptor.atlas b/sdk/benchmarks/fixtures/spine/raptor-38/raptor.atlas
new file mode 100644
index 000000000..62e1e050c
--- /dev/null
+++ b/sdk/benchmarks/fixtures/spine/raptor-38/raptor.atlas
@@ -0,0 +1,272 @@
+
+raptor.png
+size: 1024,512
+format: RGBA8888
+filter: Linear,Linear
+repeat: none
+back-arm
+ rotate: false
+ xy: 895, 295
+ size: 46, 25
+ orig: 46, 25
+ offset: 0, 0
+ index: -1
+back-bracer
+ rotate: true
+ xy: 992, 216
+ size: 39, 28
+ orig: 39, 28
+ offset: 0, 0
+ index: -1
+back-hand
+ rotate: false
+ xy: 594, 58
+ size: 36, 34
+ orig: 36, 34
+ offset: 0, 0
+ index: -1
+back-knee
+ rotate: true
+ xy: 729, 86
+ size: 49, 67
+ orig: 49, 67
+ offset: 0, 0
+ index: -1
+back-thigh
+ rotate: false
+ xy: 379, 2
+ size: 39, 24
+ orig: 39, 24
+ offset: 0, 0
+ index: -1
+eyes-open
+ rotate: true
+ xy: 902, 194
+ size: 47, 45
+ orig: 47, 45
+ offset: 0, 0
+ index: -1
+front-arm
+ rotate: false
+ xy: 945, 306
+ size: 48, 26
+ orig: 48, 26
+ offset: 0, 0
+ index: -1
+front-bracer
+ rotate: false
+ xy: 949, 197
+ size: 41, 29
+ orig: 41, 29
+ offset: 0, 0
+ index: -1
+front-hand
+ rotate: false
+ xy: 949, 266
+ size: 41, 38
+ orig: 41, 38
+ offset: 0, 0
+ index: -1
+front-open-hand
+ rotate: false
+ xy: 875, 148
+ size: 43, 44
+ orig: 43, 44
+ offset: 0, 0
+ index: -1
+front-thigh
+ rotate: true
+ xy: 793, 171
+ size: 57, 29
+ orig: 57, 29
+ offset: 0, 0
+ index: -1
+gun
+ rotate: true
+ xy: 379, 28
+ size: 107, 103
+ orig: 107, 103
+ offset: 0, 0
+ index: -1
+gun-nohand
+ rotate: false
+ xy: 487, 87
+ size: 105, 102
+ orig: 105, 102
+ offset: 0, 0
+ index: -1
+head
+ rotate: false
+ xy: 807, 361
+ size: 136, 149
+ orig: 136, 149
+ offset: 0, 0
+ index: -1
+lower-leg
+ rotate: false
+ xy: 827, 195
+ size: 73, 98
+ orig: 73, 98
+ offset: 0, 0
+ index: -1
+mouth-grind
+ rotate: true
+ xy: 920, 145
+ size: 47, 30
+ orig: 47, 30
+ offset: 0, 0
+ index: -1
+mouth-smile
+ rotate: true
+ xy: 992, 257
+ size: 47, 30
+ orig: 47, 30
+ offset: 0, 0
+ index: -1
+neck
+ rotate: false
+ xy: 359, 114
+ size: 18, 21
+ orig: 18, 21
+ offset: 0, 0
+ index: -1
+raptor-back-arm
+ rotate: false
+ xy: 653, 142
+ size: 82, 86
+ orig: 82, 86
+ offset: 0, 0
+ index: -1
+raptor-body
+ rotate: false
+ xy: 2, 277
+ size: 632, 233
+ orig: 632, 233
+ offset: 0, 0
+ index: -1
+raptor-front-arm
+ rotate: true
+ xy: 484, 4
+ size: 81, 102
+ orig: 81, 102
+ offset: 0, 0
+ index: -1
+raptor-front-leg
+ rotate: false
+ xy: 2, 18
+ size: 191, 257
+ orig: 191, 257
+ offset: 0, 0
+ index: -1
+raptor-hindleg-back
+ rotate: false
+ xy: 636, 295
+ size: 169, 215
+ orig: 169, 215
+ offset: 0, 0
+ index: -1
+raptor-horn
+ rotate: false
+ xy: 195, 22
+ size: 182, 80
+ orig: 182, 80
+ offset: 0, 0
+ index: -1
+raptor-horn-back
+ rotate: true
+ xy: 945, 334
+ size: 176, 77
+ orig: 176, 77
+ offset: 0, 0
+ index: -1
+raptor-jaw
+ rotate: false
+ xy: 359, 137
+ size: 126, 138
+ orig: 126, 138
+ offset: 0, 0
+ index: -1
+raptor-jaw-tooth
+ rotate: true
+ xy: 895, 322
+ size: 37, 48
+ orig: 37, 48
+ offset: 0, 0
+ index: -1
+raptor-mouth-inside
+ rotate: true
+ xy: 949, 228
+ size: 36, 41
+ orig: 36, 41
+ offset: 0, 0
+ index: -1
+raptor-saddle-strap-back
+ rotate: true
+ xy: 653, 86
+ size: 54, 74
+ orig: 54, 74
+ offset: 0, 0
+ index: -1
+raptor-saddle-strap-front
+ rotate: false
+ xy: 594, 94
+ size: 57, 95
+ orig: 57, 95
+ offset: 0, 0
+ index: -1
+raptor-saddle-w-shadow
+ rotate: false
+ xy: 195, 104
+ size: 162, 171
+ orig: 162, 171
+ offset: 0, 0
+ index: -1
+raptor-tail-shadow
+ rotate: false
+ xy: 636, 230
+ size: 189, 63
+ orig: 189, 63
+ offset: 0, 0
+ index: -1
+raptor-tongue
+ rotate: false
+ xy: 807, 295
+ size: 86, 64
+ orig: 86, 64
+ offset: 0, 0
+ index: -1
+stirrup-back
+ rotate: true
+ xy: 952, 151
+ size: 44, 35
+ orig: 44, 35
+ offset: 0, 0
+ index: -1
+stirrup-front
+ rotate: false
+ xy: 902, 243
+ size: 45, 50
+ orig: 45, 50
+ offset: 0, 0
+ index: -1
+stirrup-strap
+ rotate: false
+ xy: 824, 147
+ size: 49, 46
+ orig: 49, 46
+ offset: 0, 0
+ index: -1
+torso
+ rotate: false
+ xy: 737, 137
+ size: 54, 91
+ orig: 54, 91
+ offset: 0, 0
+ index: -1
+visor
+ rotate: false
+ xy: 487, 191
+ size: 131, 84
+ orig: 131, 84
+ offset: 0, 0
+ index: -1
diff --git a/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy-pro.skel b/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy-pro.skel
new file mode 100644
index 000000000..df612671d
Binary files /dev/null and b/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy-pro.skel differ
diff --git a/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy.atlas b/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy.atlas
new file mode 100644
index 000000000..a2a83fea3
--- /dev/null
+++ b/sdk/benchmarks/fixtures/spine/spineboy-38/spineboy.atlas
@@ -0,0 +1,286 @@
+
+spineboy.png
+size: 1024,256
+format: RGBA8888
+filter: Linear,Linear
+repeat: none
+crosshair
+ rotate: false
+ xy: 352, 7
+ size: 45, 45
+ orig: 45, 45
+ offset: 0, 0
+ index: -1
+eye-indifferent
+ rotate: false
+ xy: 862, 105
+ size: 47, 45
+ orig: 47, 45
+ offset: 0, 0
+ index: -1
+eye-surprised
+ rotate: false
+ xy: 505, 79
+ size: 47, 45
+ orig: 47, 45
+ offset: 0, 0
+ index: -1
+front-bracer
+ rotate: false
+ xy: 826, 66
+ size: 29, 40
+ orig: 29, 40
+ offset: 0, 0
+ index: -1
+front-fist-closed
+ rotate: false
+ xy: 786, 65
+ size: 38, 41
+ orig: 38, 41
+ offset: 0, 0
+ index: -1
+front-fist-open
+ rotate: true
+ xy: 710, 51
+ size: 43, 44
+ orig: 43, 44
+ offset: 0, 0
+ index: -1
+front-foot
+ rotate: false
+ xy: 210, 6
+ size: 63, 35
+ orig: 63, 35
+ offset: 0, 0
+ index: -1
+front-shin
+ rotate: true
+ xy: 665, 128
+ size: 41, 92
+ orig: 41, 92
+ offset: 0, 0
+ index: -1
+front-thigh
+ rotate: true
+ xy: 2, 2
+ size: 23, 56
+ orig: 23, 56
+ offset: 0, 0
+ index: -1
+front-upper-arm
+ rotate: false
+ xy: 250, 205
+ size: 23, 49
+ orig: 23, 49
+ offset: 0, 0
+ index: -1
+goggles
+ rotate: false
+ xy: 665, 171
+ size: 131, 83
+ orig: 131, 83
+ offset: 0, 0
+ index: -1
+gun
+ rotate: false
+ xy: 798, 152
+ size: 105, 102
+ orig: 105, 102
+ offset: 0, 0
+ index: -1
+head
+ rotate: false
+ xy: 2, 27
+ size: 136, 149
+ orig: 136, 149
+ offset: 0, 0
+ index: -1
+hoverboard-board
+ rotate: false
+ xy: 2, 178
+ size: 246, 76
+ orig: 246, 76
+ offset: 0, 0
+ index: -1
+hoverboard-thruster
+ rotate: true
+ xy: 722, 96
+ size: 30, 32
+ orig: 30, 32
+ offset: 0, 0
+ index: -1
+hoverglow-small
+ rotate: false
+ xy: 275, 81
+ size: 137, 38
+ orig: 137, 38
+ offset: 0, 0
+ index: -1
+mouth-grind
+ rotate: false
+ xy: 614, 97
+ size: 47, 30
+ orig: 47, 30
+ offset: 0, 0
+ index: -1
+mouth-oooo
+ rotate: false
+ xy: 612, 65
+ size: 47, 30
+ orig: 47, 30
+ offset: 0, 0
+ index: -1
+mouth-smile
+ rotate: false
+ xy: 661, 64
+ size: 47, 30
+ orig: 47, 30
+ offset: 0, 0
+ index: -1
+muzzle-glow
+ rotate: false
+ xy: 382, 54
+ size: 25, 25
+ orig: 25, 25
+ offset: 0, 0
+ index: -1
+muzzle-ring
+ rotate: true
+ xy: 275, 54
+ size: 25, 105
+ orig: 25, 105
+ offset: 0, 0
+ index: -1
+muzzle01
+ rotate: true
+ xy: 911, 95
+ size: 67, 40
+ orig: 67, 40
+ offset: 0, 0
+ index: -1
+muzzle02
+ rotate: false
+ xy: 792, 108
+ size: 68, 42
+ orig: 68, 42
+ offset: 0, 0
+ index: -1
+muzzle03
+ rotate: true
+ xy: 956, 171
+ size: 83, 53
+ orig: 83, 53
+ offset: 0, 0
+ index: -1
+muzzle04
+ rotate: false
+ xy: 275, 7
+ size: 75, 45
+ orig: 75, 45
+ offset: 0, 0
+ index: -1
+muzzle05
+ rotate: false
+ xy: 140, 3
+ size: 68, 38
+ orig: 68, 38
+ offset: 0, 0
+ index: -1
+neck
+ rotate: false
+ xy: 250, 182
+ size: 18, 21
+ orig: 18, 21
+ offset: 0, 0
+ index: -1
+portal-bg
+ rotate: false
+ xy: 140, 43
+ size: 133, 133
+ orig: 133, 133
+ offset: 0, 0
+ index: -1
+portal-flare1
+ rotate: false
+ xy: 554, 65
+ size: 56, 30
+ orig: 56, 30
+ offset: 0, 0
+ index: -1
+portal-flare2
+ rotate: true
+ xy: 759, 112
+ size: 57, 31
+ orig: 57, 31
+ offset: 0, 0
+ index: -1
+portal-flare3
+ rotate: false
+ xy: 554, 97
+ size: 58, 30
+ orig: 58, 30
+ offset: 0, 0
+ index: -1
+portal-shade
+ rotate: false
+ xy: 275, 121
+ size: 133, 133
+ orig: 133, 133
+ offset: 0, 0
+ index: -1
+portal-streaks1
+ rotate: false
+ xy: 410, 126
+ size: 126, 128
+ orig: 126, 128
+ offset: 0, 0
+ index: -1
+portal-streaks2
+ rotate: false
+ xy: 538, 129
+ size: 125, 125
+ orig: 125, 125
+ offset: 0, 0
+ index: -1
+rear-bracer
+ rotate: false
+ xy: 857, 67
+ size: 28, 36
+ orig: 28, 36
+ offset: 0, 0
+ index: -1
+rear-foot
+ rotate: false
+ xy: 663, 96
+ size: 57, 30
+ orig: 57, 30
+ offset: 0, 0
+ index: -1
+rear-shin
+ rotate: true
+ xy: 414, 86
+ size: 38, 89
+ orig: 38, 89
+ offset: 0, 0
+ index: -1
+rear-thigh
+ rotate: false
+ xy: 756, 63
+ size: 28, 47
+ orig: 28, 47
+ offset: 0, 0
+ index: -1
+rear-upper-arm
+ rotate: true
+ xy: 60, 5
+ size: 20, 44
+ orig: 20, 44
+ offset: 0, 0
+ index: -1
+torso
+ rotate: false
+ xy: 905, 164
+ size: 49, 90
+ orig: 49, 90
+ offset: 0, 0
+ index: -1
diff --git a/sdk/benchmarks/spine.bench.ts b/sdk/benchmarks/spine.bench.ts
new file mode 100644
index 000000000..177303fb5
--- /dev/null
+++ b/sdk/benchmarks/spine.bench.ts
@@ -0,0 +1,686 @@
+import { describe, bench, beforeAll } from 'vitest';
+import path from 'path';
+import fs from 'fs';
+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';
+
+const WASM_DIR = path.resolve(__dirname, '../../desktop/public/wasm');
+const SPINE_ASSETS = path.resolve(__dirname, 'fixtures/spine');
+
+let raw: SpineWasmModule;
+let api: SpineWrappedAPI;
+let controller: SpineModuleController;
+let coreModule: ESEngineModule;
+
+let spineboySkel: Uint8Array;
+let spineboyAtlas: string;
+let raptorSkel: Uint8Array;
+let raptorAtlas: string;
+let coinSkel: Uint8Array;
+let coinAtlas: string;
+
+beforeAll(async () => {
+ const jsPath = path.join(WASM_DIR, 'spine38.js');
+ const mod = await import(jsPath);
+ const wasmBytes = fs.readFileSync(path.join(WASM_DIR, 'spine38.wasm'));
+ raw = await mod.default({
+ instantiateWasm(imports: WebAssembly.Imports, cb: Function) {
+ WebAssembly.instantiate(wasmBytes, imports).then(
+ (r: WebAssembly.WebAssemblyInstantiatedSource) => cb(r.instance, r.module),
+ );
+ return {};
+ },
+ }) as SpineWasmModule;
+ 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;
+
+ 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');
+ raptorSkel = fs.readFileSync(path.join(SPINE_ASSETS, 'raptor-38/raptor-pro.skel'));
+ raptorAtlas = fs.readFileSync(path.join(SPINE_ASSETS, 'raptor-38/raptor.atlas'), 'utf-8');
+ coinSkel = fs.readFileSync(path.join(SPINE_ASSETS, 'coin-38/coin-pro.skel'));
+ coinAtlas = fs.readFileSync(path.join(SPINE_ASSETS, 'coin-38/coin.atlas'), 'utf-8');
+});
+
+function loadAndSetup(skel: Uint8Array, atlas: string): { skelHandle: number; instanceId: number } {
+ const skelHandle = controller.loadSkeleton(skel, atlas, true);
+ const pageCount = controller.getAtlasPageCount(skelHandle);
+ for (let i = 0; i < pageCount; i++) {
+ controller.setAtlasPageTexture(skelHandle, i, 1, 512, 512);
+ }
+ const instanceId = controller.createInstance(skelHandle);
+ return { skelHandle, instanceId };
+}
+
+function loadNInstances(skel: Uint8Array, atlas: string, n: number): { skelHandle: number; instances: number[] } {
+ const skelHandle = controller.loadSkeleton(skel, atlas, true);
+ const pageCount = controller.getAtlasPageCount(skelHandle);
+ for (let i = 0; i < pageCount; i++) {
+ controller.setAtlasPageTexture(skelHandle, i, 1, 512, 512);
+ }
+ const instances: number[] = [];
+ for (let i = 0; i < n; i++) {
+ instances.push(controller.createInstance(skelHandle));
+ }
+ return { skelHandle, instances };
+}
+
+function cleanupInstances(skelHandle: number, instances: number[]) {
+ for (const id of instances) controller.destroyInstance(id);
+ controller.unloadSkeleton(skelHandle);
+}
+
+// =============================================================================
+// Skeleton loading
+// =============================================================================
+
+describe('Spine: skeleton loading', () => {
+ bench('load coin (2.4K skel, simple)', () => {
+ const h = controller.loadSkeleton(coinSkel, coinAtlas, true);
+ controller.unloadSkeleton(h);
+ });
+
+ bench('load spineboy (60K skel, medium)', () => {
+ const h = controller.loadSkeleton(spineboySkel, spineboyAtlas, true);
+ controller.unloadSkeleton(h);
+ });
+
+ bench('load raptor (59K skel, complex)', () => {
+ const h = controller.loadSkeleton(raptorSkel, raptorAtlas, true);
+ controller.unloadSkeleton(h);
+ });
+});
+
+// =============================================================================
+// Instance creation
+// =============================================================================
+
+describe('Spine: instance creation', () => {
+ bench('create 1 spineboy instance', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 1);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('create 10 spineboy instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 10);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('create 50 spineboy instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 50);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('create 100 spineboy instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+// =============================================================================
+// Animation update (the hot loop)
+// =============================================================================
+
+describe('Spine: animation update - spineboy', () => {
+ const DT = 1 / 60;
+
+ bench('update 1 instance', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 1);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 10 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 10);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 50 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 50);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 100 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 500 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 500);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 1000 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 1000);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+describe('Spine: animation update - raptor (complex)', () => {
+ const DT = 1 / 60;
+
+ bench('update 10 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 10);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 50 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 50);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 100 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 100);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('update 500 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 500);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+// =============================================================================
+// Mesh extraction (measures vertex generation overhead)
+// =============================================================================
+
+describe('Spine: mesh extraction - spineboy', () => {
+ const DT = 1 / 60;
+
+ bench('extract 1 instance', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 1);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 10 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 10);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 50 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 50);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 100 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 500 instances', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 500);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+describe('Spine: mesh extraction - raptor (complex)', () => {
+ const DT = 1 / 60;
+
+ bench('extract 10 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 10);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 50 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 50);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('extract 100 raptor instances', () => {
+ const { skelHandle, instances } = loadNInstances(raptorSkel, raptorAtlas, 100);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (const id of instances) controller.extractMeshBatches(id);
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+// =============================================================================
+// Full frame simulation (update + extract, measures per-frame budget)
+// =============================================================================
+
+describe('Spine: full frame (update + extract) - spineboy', () => {
+ const DT = 1 / 60;
+
+ bench('1 instance per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 1);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('10 instances per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 10);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('50 instances per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 50);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 instances per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('200 instances per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 200);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('500 instances per frame x60', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 500);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) {
+ controller.update(id, DT);
+ controller.extractMeshBatches(id);
+ }
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+// =============================================================================
+// Vertex count report (not a perf bench, just data collection)
+// =============================================================================
+
+describe('Spine: vertex/batch statistics', () => {
+ bench('spineboy mesh stats', () => {
+ 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.destroyInstance(instanceId);
+ controller.unloadSkeleton(skelHandle);
+ });
+
+ bench('raptor mesh stats', () => {
+ 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.destroyInstance(instanceId);
+ controller.unloadSkeleton(skelHandle);
+ });
+
+ bench('coin mesh stats', () => {
+ 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.destroyInstance(instanceId);
+ controller.unloadSkeleton(skelHandle);
+ });
+});
+
+// =============================================================================
+// Engine overhead: isolate JS→WASM data copy + submit cost
+// =============================================================================
+
+type CachedBatchEntry = {
+ vertices: Float32Array;
+ indices: Uint16Array;
+ textureId: number;
+ blendMode: number;
+ entity: number;
+ skeletonScale: number;
+ flipX: boolean;
+ flipY: boolean;
+ layer: number;
+};
+
+function prepareExtractedBatches(
+ skel: Uint8Array, atlas: string, n: number, animation: string,
+): { skelHandle: number; instances: number[]; entries: CachedBatchEntry[] } {
+ const { skelHandle, instances } = loadNInstances(skel, atlas, n);
+ for (const id of instances) {
+ controller.play(id, animation, true);
+ controller.update(id, 1 / 60);
+ }
+ 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,
+ });
+ }
+ }
+ return { skelHandle, instances, entries };
+}
+
+function simulateDataCopyOnly(entries: CachedBatchEntry[]) {
+ let totalVertBytes = 0;
+ let totalIdxBytes = 0;
+ for (const e of entries) {
+ totalVertBytes += e.vertices.byteLength;
+ totalIdxBytes += e.indices.byteLength;
+ }
+
+ const vertBase = coreModule._malloc(totalVertBytes);
+ const idxBase = coreModule._malloc(totalIdxBytes);
+
+ let vOff = 0;
+ let iOff = 0;
+ for (const e of entries) {
+ const vertPtr = vertBase + vOff;
+ const idxPtr = idxBase + iOff;
+ coreModule.HEAPF32.set(e.vertices, vertPtr >> 2);
+ new Uint16Array(coreModule.HEAPU8.buffer, idxPtr, e.indices.length).set(e.indices);
+ vOff += e.vertices.byteLength;
+ iOff += e.indices.byteLength;
+ }
+
+ coreModule._free(vertBase);
+ coreModule._free(idxBase);
+}
+
+function simulateDataCopyAndSubmit(entries: CachedBatchEntry[]) {
+ const submitFn = coreModule.renderer_submitSpineBatchByEntity;
+ const registry = new coreModule.Registry();
+
+ let totalVertBytes = 0;
+ let totalIdxBytes = 0;
+ for (const e of entries) {
+ totalVertBytes += e.vertices.byteLength;
+ totalIdxBytes += e.indices.byteLength;
+ }
+
+ const vertBase = coreModule._malloc(totalVertBytes);
+ const idxBase = coreModule._malloc(totalIdxBytes);
+
+ let vOff = 0;
+ let iOff = 0;
+ for (const e of entries) {
+ const vertPtr = vertBase + vOff;
+ const idxPtr = idxBase + iOff;
+ coreModule.HEAPF32.set(e.vertices, vertPtr >> 2);
+ new Uint16Array(coreModule.HEAPU8.buffer, idxPtr, e.indices.length).set(e.indices);
+
+ if (submitFn) {
+ submitFn.call(coreModule, registry,
+ vertPtr, e.vertices.length / 8,
+ idxPtr, e.indices.length,
+ e.textureId, e.blendMode,
+ e.entity, e.skeletonScale, e.flipX, e.flipY,
+ e.layer, 0);
+ }
+
+ vOff += e.vertices.byteLength;
+ iOff += e.indices.byteLength;
+ }
+
+ coreModule._free(vertBase);
+ coreModule._free(idxBase);
+ registry.delete();
+}
+
+describe('Engine overhead: JS→WASM data copy (malloc+memcpy+free)', () => {
+ bench('10 spineboy - data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 10, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('50 spineboy - data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 50, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 spineboy - data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 100, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('200 spineboy - data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 200, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('500 spineboy - data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 500, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+describe('Engine overhead: data copy + renderer submit', () => {
+ bench('10 spineboy - copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 10, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('50 spineboy - copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 50, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 spineboy - copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 100, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('200 spineboy - copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 200, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('500 spineboy - copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 500, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});
+
+describe('Engine overhead: proportion (Spine update vs engine copy+submit)', () => {
+ const DT = 1 / 60;
+
+ bench('100 spineboy - Spine update only (baseline)', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ for (const id of instances) controller.play(id, 'walk', true);
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.update(id, DT);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 spineboy - Spine extract only', () => {
+ const { skelHandle, instances } = loadNInstances(spineboySkel, spineboyAtlas, 100);
+ for (const id of instances) {
+ controller.play(id, 'walk', true);
+ controller.update(id, DT);
+ }
+ for (let frame = 0; frame < 60; frame++) {
+ for (const id of instances) controller.extractMeshBatches(id);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 spineboy - engine data copy only', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 100, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyOnly(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+
+ bench('100 spineboy - engine copy + submit', () => {
+ const { skelHandle, instances, entries } = prepareExtractedBatches(spineboySkel, spineboyAtlas, 100, 'walk');
+ for (let frame = 0; frame < 60; frame++) {
+ simulateDataCopyAndSubmit(entries);
+ }
+ cleanupInstances(skelHandle, instances);
+ });
+});