Benchmarks

View Source

This 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

whatmedian (us)p99 (us)
inspect calculator (13 KB)99.9136.8
load and unload calculator3092.324375.8
inspect data_transform (49 KB)227.7311.5
load and unload data_transform8992.030054.0
inspect http_client (85 KB)705.2797.0
load and unload http_client14085.826279.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

whatmedian (us)p99 (us)
calculator add: direct_inline110.3235.7
calculator add: direct_spawned290.3421.3
calculator add: wasm_tools:call/3227.4410.6
calculator add: through a registry230.8399.8
data_transform normalize: direct_inline463.9769.1
data_transform normalize: wasm_tools:call/31090.41389.7
  • direct_inline is erlang_wasm alone in the calling process: instantiate, call, destroy. It cannot be stopped by a deadline or a cancel. direct_spawned is 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_wordsmedian (us)calls/s, 1 caller8 callers64 callers
0291 to 3003,38318,558 to 19,84820,490 to 23,719
81922354,28421,60824,439
16384 (default)236 to 2384,252 to 4,35223,930 to 24,45124,125 to 24,666
327682284,39518,6468,925
65536228 to 2304,321 to 4,47821,810 to 22,98316,197 to 17,021

data_transform normalize, a record in and out, spawned with erlang_wasm alone:

min_heap_wordsmedian (us)
01024
16384896
65536618
262144506
  • 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:

callersrate
14,409 calls/s
825,270 calls/s
6424,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

whatmedian (us)p99 (us)
native call through the registry226.7357.0
wasm_tools_mcp:handle/2 (JSON in and out)231.3309.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.