Page-backed linear-memory backend, a thin shim over the Erlang
:wa_embedder_memory_ets implementation.
Each 64 KiB page is its own ETS entry, so a store costs O(page) rather than
O(total memory). Measured against WaEmbedder.Memory.Binary on Apple
silicon/OTP 27, 4-byte stores:
| Memory | Binary | ETS |
|---|---|---|
| 256 KiB | 4.4 us | 1.6 us |
| 1 MiB | 14.1 us | 1.6 us |
| 4 MiB | 73.0 us | 1.5 us |
| 16 MiB | 253.0 us | 1.8 us |
| 64 MiB | 1070.2 us | 2.0 us |
The cost is flat in memory size rather than linear, which is what makes it usable for a garbage-collected runtime such as QuickJS.
Use it as the :memory compile option:
:wa_embedder.compile(path, memory: WaEmbedder.Memory.ETS)The reference is the opaque %{table: ref, pages: n, max: max} map produced
by the Erlang backend; out-of-bounds access traps via
:erlang.error({:wasm_trap, :memory_oob, %{addr: addr, width: width}}).
Reference semantics
The behaviour requires every callback to return a ref(), and generated code
threads that return value through. Unlike WaEmbedder.Memory.Binary, which
returns a fresh immutable map, this backend mutates one ETS table, so the ref
returned by new/2 and the one returned by store/5 address the same table.
Callers must still use the returned ref — discarding it happens to work here
but is not part of the contract.