Metabolism: decision-cadence (think slower than you move) + empty-block skip; flat typed-array bytecode; WebGPU decision-layer slice (experimental) + heavy-world benchmark

This commit is contained in:
Dejvino
2026-10-28 13:51:58 +01:00
parent 476fa1833a
commit 3a72525ccb
7 changed files with 608 additions and 43 deletions
+36
View File
@@ -0,0 +1,36 @@
// The heavy-world benchmark: same song, same seed, same planted population —
// only the decision cadence varies. Sim-only (no render), field 128.
import { buildSong } from '../src/song/song.js';
import { analyse } from '../src/audio/analyse.js';
import { decodeWav, mono } from '../src/audio/wav.js';
import { World } from '../src/sim/world.js';
import { readFileSync } from 'node:fs';
const name = process.argv[2] ?? 'runner';
const frames = Number(process.argv[3] ?? 300);
const wav = decodeWav(readFileSync(new URL(`../../flow-state/test/songs/${name}.wav`, import.meta.url)));
const song = buildSong(analyse(mono(wav.channels), wav.sampleRate), 12345);
function plant(w) {
// identical starting points: a dense 80×80 metropolis west of centre
const F = w.field;
for (let y = 24; y < 104; y++) {
for (let x = 24; x < 104; x++) {
const i = y * F + x;
for (let s = 0; s < w.m; s++) w.pop[s][i] = 1.6;
}
}
w.recount();
}
for (const vmEvery of [1, 2, 3]) {
const w = new World(song, { fps: 30, field: 128, genesis: 0, vmEvery });
plant(w);
const start = w.count;
// warm-up
for (let f = 0; f < 30; f++) w.step();
const t0 = process.hrtime.bigint();
for (let f = 0; f < frames; f++) w.step();
const ms = Number(process.hrtime.bigint() - t0) / 1e6 / frames;
console.log(`vmEvery=${vmEvery} sim ${ms.toFixed(1)} ms/frame (start ${Math.round(start)}, now ${Math.round(w.count)}, peak-ish budget ${Math.round(w.cap).toLocaleString()})`);
}