aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorgbc dev <gbc@localhost>2026-09-22 20:48:09 +0200
committergbc dev <gbc@localhost>2026-09-22 20:48:09 +0200
commita2aa8fbb20cab296d44bcdd23c63c0f76ec52869 (patch)
tree700f7a394f8bceb27199590343b158e872e1404d /web
parentweb: selecting a Game Boy puts the caret in its console (diff)
downloadsl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.tar.gz
sl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.tar.xz
sl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.zip
wasm: cap the stack at 256KB - 16.25MB -> 0.5MB per Game Boy
zig defaults the wasm stack to 16MB, and that lands in the module's *initial* memory, so every instance allocated 16.25MB before executing an instruction. With several Game Boys on one page that was the dominant cost: 123MB for six. The machine is a static and nothing here recurses deeply, so 256KB is plenty. Per instance: 20.5MB -> 4.8MB of linear memory (six: 123MB -> 29MB). Note the spelling - zig cc rejects -Wl,--stack-size and -zstack-size, and wants -Wl,-z,stack-size=N. With memory no longer the constraint, the page cap goes 6 -> 8 on measurement rather than guesswork. Emulation-only, one thread: 12.5x realtime at 1, 3.1x at 4, 1.5x at 8, and exactly 1.0x at 12 - i.e. ~12 is where a thread runs out of road with nothing left for rendering. 8 holds a verified 60fps each in a real browser with all eight leased. Golden frames are still pixel-exact on cgb-acid2, dmg-acid2, cpu_instrs@600 and pky@400 with its .sav, and two Game Boys still lease and ping 4/4.
Diffstat (limited to 'web')
-rw-r--r--web/gbcore.js2
-rw-r--r--web/index.html2
2 files changed, 3 insertions, 1 deletions
diff --git a/web/gbcore.js b/web/gbcore.js
index 637b939..8cecb82 100644
--- a/web/gbcore.js
+++ b/web/gbcore.js
@@ -110,6 +110,8 @@ export class GameBoy {
this.#ex.gbw_serial_push(bytes.length);
}
get serialDropped() { return this.#ex.gbw_serial_dropped(); }
+ // This machine's share of wasm linear memory - what N Game Boys really cost.
+ get memBytes() { return this.#ex.memory.buffer.byteLength; }
// ---- battery RAM ----
sram() {
diff --git a/web/index.html b/web/index.html
index d182b57..1d28c89 100644
--- a/web/index.html
+++ b/web/index.html
@@ -96,7 +96,7 @@ import { GameBoy, BTN } from "./gbcore.js";
import { Hub, ipStr, GW } from "./gbhub.js";
const $ = (id) => document.getElementById(id);
-const MAX_GB = 6; // one thread runs ~12 at full speed; leave headroom
+const MAX_GB = 8; // CPU-bound: ~12 fit in one thread with zero headroom
const ROM_URL = "roms/gbos.gb";
const logEl = $("log");