GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wasm-split-tool/examples at main · AnranS/wasm-split-tool

Expand file tree

/

examples

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

examples

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
browser-archive
browser-archive
 
 
browser-vanilla
browser-vanilla
 
 
node-load
node-load
 
 
01-split-manual.sh
01-split-manual.sh
 
 
02-archive-mode.sh
02-archive-mode.sh
 
 
03-profile-driven.sh
03-profile-driven.sh
 
 
04-complex-demo.sh
04-complex-demo.sh
 
 
README.md
README.md
 
 
demo.split.funcidx.txt
demo.split.funcidx.txt
 
 
demo.split.txt
demo.split.txt
 
 
demo.wat
demo.wat
 
 
game-verify.mjs
game-verify.mjs
 
 
game.split.txt
game.split.txt
 
 
game.wat
game.wat
 
 

README.md

Outline

Examples

Runnable, end-to-end walkthroughs of everything this toolchain can do.

Layout

examples/
├── demo.wat                    minimal 4-func module (scripts 01-03)
├── demo.split.txt              cold list (names, readable)
├── demo.split.funcidx.txt      cold list (funcidxs, for stripped builds)
├── game.wat                    richer 12-func module (script 04)
├── game.split.txt              cold list for game.wat (9 cold funcs)
│
├── 01-split-manual.sh          CLI: classic split, hand-written cold list
├── 02-archive-mode.sh          CLI: archive mode + Brotli / batch-size comparison
├── 03-profile-driven.sh        CLI: full prepare → collect → split pipeline
├── 04-complex-demo.sh          CLI + runtime: rich module end-to-end, asserts results
│
├── game-verify.mjs             Node verifier called from 04 (asserts every export)
│
├── browser-vanilla/            Runtime: split mode in a plain <script type="module">
├── browser-archive/            Runtime: archive mode + trampolineFill toggle + evict button
└── node-load/                  Runtime: programmatic load from Node, both modes

CLI scripts

Each .sh is self-contained. Run from the repo root; output goes into examples/out/<name>/ (gitignored).

# script shows
01 01-split-manual.sh Classic split on a hand-written cold list (--cold-list + --output-dir). Produces primary.wasm + secondary.wasm + split-manifest.json from demo.wat.
02 02-archive-mode.sh iOS-optimized archive mode. Produces primary.archive.wasm + func_archive.bin + archive-manifest.json. Compares archive sizes with/without Brotli, and with different --batch-size values.
03 03-profile-driven.sh Full profile-driven pipeline: prepare → run instrumented wasm against a backgrounded collect over HTTP → split --hot-list. No hand-written cold list.
04 04-complex-demo.sh End-to-end on the richer game.wat. Emits split + archive + archive/batch_size=3 builds, then runs game-verify.mjs which instantiates the archive and asserts every cold/hot export's return value. Exercises cold→hot rewrite, cold→cold rewrite, type-deduplicated trampolines (4 type groups for 9 cold funcs), multi-batch archives, and evict + re-inject.

Prerequisites for the CLI scripts

# Rust CLI
cargo build --release --bin wasm-split

# wat → wasm converter (used by every script)
#   macOS:  brew install wabt
#   Ubuntu: sudo apt install wabt

All scripts assume ./target/release/wasm-split and wat2wasm are on PATH. Override with WASM_SPLIT=/path/to/wasm-split ./examples/01-…sh if you keep the binary elsewhere.

Runtime (browser / Node) demos

All three runtime demos consume the fixtures under runtime/test/fixtures/, so they run out of the box once you've built the TS package:

cd runtime && npm install && npm run build
directory mode entry point
browser-vanilla split (primary + secondary) browser-vanilla/index.html
browser-archive archive (primary + func_archive.bin) browser-archive/index.html
node-load both, programmatic node-load/run.mjs

Browser demos

Serve the repo root with any static server (the HTML pages use relative paths that reach into ../../runtime/dist/ and ../../runtime/test/fixtures/):

# From the repo root:
npx serve .
#   → http://localhost:3000/examples/browser-vanilla/
#   → http://localhost:3000/examples/browser-archive/

Opening the HTML file directly (file://…) won't work — browsers block fetch() against file:// URLs.

Node demo

# From the repo root:
node examples/node-load/run.mjs

Requires Node ≥ 18. The script reads the fixture files with fs/promises and hands bytes to the loader directly, so it needs no HTTP server at all.

Using your own build outputs

Every demo points at ../../runtime/test/fixtures/… so you have something to run immediately. To swap in the output of your own wasm-split split or wasm-split archive invocation (e.g. the artifacts produced by the CLI scripts above in examples/out/…), edit the path constants near the top of each entry point:

// browser-archive/index.html
const PRIMARY  = '/path/to/primary.wasm';
const ARCHIVE  = '/path/to/func_archive.bin';
const MANIFEST = '/path/to/archive-manifest.json';
// node-load/run.mjs
const FIX = '/path/to/your/wasm-split/output';

The demo modules

Scripts 01-03 operate on demo.wat, a minimal 4-function toy (same module the Rust unit tests bake into end_to_end.rs):

funcidx 0 = $hot    (hot)    n → n + 1
funcidx 1 = $cold_a (cold)   n → n * 100
funcidx 2 = $cold_b (cold)   n → n + 7
funcidx 3 = $hot2   (hot)    n → n << 2

Script 04 uses game.wat — a 12-function "mini-game" module designed to exercise every non-trivial code path in archive mode:

# name hot? type signature notes
0 frame_step hot (i32)→i32 mutates $frame_count global
1 entity_update hot (i32,i32)→() writes to memory
2 rand hot ()→i32 LCG, mutates $rand_state global
3 open_inventory cold (i32)→i32 cold → hot direct call (to rand)
4 boss_battle_init cold (i32)→i32 cold → cold direct call (to open_inventory)
5 save_game cold (i32)→() writes data-segment-backed memory
6 load_game cold (i32)→i32 reads save slot
7 settings_apply cold (i32,i32)→i32 two-arg type
8 achievement_unlock cold (i32,i32)→i32 cold → cold direct call (to save_game)
9 credits_show cold ()→i32 no-arg type
10 credits_version cold ()→i32 same signature as credits_show (dedup)
11 debug_dump cold (i32)→() same signature as save_game (dedup)

What this module proves end-to-end:

  • Trampoline type dedup: 9 cold functions collapse into exactly 4 trampoline WebAssembly.Instances (one per type signature), regardless of cold-count. The verifier asserts this on archiveFillReport.modulesInstantiated.
  • Direct-call rewriting: the splitter logs rewrote 1 direct cold->hot call sites to call_indirect and archive secondary: rewrote 3 direct cold call sites to waitTableId+call_indirect.
  • Batching: with --batch-size 3 the same archive (same byte count) is served as 3 body batches instead of 1. You can observe more trampoline hits at runtime (onColdHit fires once per batch; the event is a discriminated union — use ev.mode === 'archive' to access ev.trampolinesReady).
  • Evict + re-inject: after archive.evictByTableIndex(3), the next open_inventory() call causes the trampoline to fire again and a fresh micro-module is synthesized.

Cleanup

rm -rf examples/out
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.