Benchmarks
View SourceThis page records what a call costs, measured, so you can judge whether
wasm_tools fits a use and so a change that makes it slower is seen. Each figure
comes from test/wasm_tools_bench_SUITE.erl on one machine; they are orders of
magnitude to compare, not promises.
Run them
rebar3 ct --suite=test/wasm_tools_bench_SUITE --group=bench
Each case logs a table to its Common Test log (_build/test/logs/).
Copy them here with the machine and the OTP version.
The machine
Apple M4 Pro, 14 cores (14 schedulers online), macOS, Erlang/OTP 29.1.3 (ERTS 17.1.2), erlang_wasm 0.15.0, interpreter only (the untrusted limits keep fuel, so the compiled tier is off). Measured 2026-11-30.
Each timing is the median and the 99th percentile of 2000 runs (100 for inspect, 20 for load), in microseconds.
Inspect and load
| what | median (us) | p99 (us) |
|---|---|---|
| inspect calculator (13 KB) | 99.9 | 136.8 |
| load and unload calculator | 3092.3 | 24375.8 |
| inspect data_transform (49 KB) | 227.7 | 311.5 |
| load and unload data_transform | 8992.0 | 30054.0 |
| inspect http_client (85 KB) | 705.2 | 797.0 |
| load and unload http_client | 14085.8 | 26279.3 |
- Load decodes, checks and compiles the component's core modules once; after that every call reuses them.
- erlang_wasm loads at most 50 modules a second on a node
(
max_module_loads_per_second). Past it a load answers#{class := overloaded, kind := load_rate_exceeded}for the rest of that second, so the loads above are spaced out. Load components at start, not per request.
Call latency
| what | median (us) | p99 (us) |
|---|---|---|
| calculator add: direct_inline | 110.3 | 235.7 |
| calculator add: direct_spawned | 290.3 | 421.3 |
| calculator add: wasm_tools:call/3 | 227.4 | 410.6 |
| calculator add: through a registry | 230.8 | 399.8 |
| data_transform normalize: direct_inline | 463.9 | 769.1 |
| data_transform normalize: wasm_tools:call/3 | 1090.4 | 1389.7 |
direct_inlineis erlang_wasm alone in the calling process: instantiate, call, destroy. It cannot be stopped by a deadline or a cancel.direct_spawnedis the same in a fresh process, with no heap floor.- A wasm_tools call adds a runner and a watchdog process, the argument check
and the deadline, and still costs less than
direct_spawned, because its runner starts with a heap floor (below). - A registry adds one message to check the tool out: a few microseconds.
Heap floor
A fresh process that instantiates a component grows its heap step by step;
that is most of the gap between direct_inline and direct_spawned. The
runner starts with min_heap_words (16384 words, 128 KiB, by default).
calculator add, one call at a time and at several concurrent callers:
| min_heap_words | median (us) | calls/s, 1 caller | 8 callers | 64 callers |
|---|---|---|---|---|
| 0 | 291 to 300 | 3,383 | 18,558 to 19,848 | 20,490 to 23,719 |
| 8192 | 235 | 4,284 | 21,608 | 24,439 |
| 16384 (default) | 236 to 238 | 4,252 to 4,352 | 23,930 to 24,451 | 24,125 to 24,666 |
| 32768 | 228 | 4,395 | 18,646 | 8,925 |
| 65536 | 228 to 230 | 4,321 to 4,478 | 21,810 to 22,983 | 16,197 to 17,021 |
data_transform normalize, a record in and out, spawned with erlang_wasm alone:
| min_heap_words | median (us) |
|---|---|
| 0 | 1024 |
| 16384 | 896 |
| 65536 | 618 |
| 262144 | 506 |
- The default gives most of the gain on small calls and the best throughput
under many concurrent calls. A larger floor helps components that pass large
values, at the cost of memory held by each running call, which lowers
throughput when many run at once. Raise it per component with
limits => #{min_heap_words => W}.
Throughput
calculator add, 20,000 calls shared among the callers, each call waited for:
| callers | rate |
|---|---|
| 1 | 4,409 calls/s |
| 8 | 25,270 calls/s |
| 64 | 24,226 calls/s |
Memory
A runner during a call of custom_host's run, read from inside the call by a
host function: 365 KB of process memory (heap and stack). The component's
linear memory and compiled code are not in that figure; erlang_wasm accounts
for linear memory per node (wasm_engine:stats/0).
MCP adapter
| what | median (us) | p99 (us) |
|---|---|---|
| native call through the registry | 226.7 | 357.0 |
| wasm_tools_mcp:handle/2 (JSON in and out) | 231.3 | 309.9 |
The handler is called as barrel_mcp calls it, without HTTP: it converts the JSON arguments, makes the same call, and converts the result. The protocol and the transport are barrel_mcp's and come on top.