Advanced

When WASM is not worth it

A module costs startup, memory, and crossings. If the work inside is small, those costs are larger than the work, and the design is a loss rather than a win.

What you will see

One line with both numbers. A refusal with numbers is a decision that can be revisited.

About 1 min of reading

Try It

Compare work to overhead

1

Write the two numbers

printf 'work_us 40 overhead_us 120\n' > /tmp/k.txt; awk '{printf "%.2f\n", $3/$2}' /tmp/k.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3.00. Overhead is three times the work, which is the shape of a loss.
2

Amortise the overhead

printf 'work_us 40000 overhead_us 120\n' > /tmp/k2.txt; awk '{printf "%.4f\n", $3/$2}' /tmp/k2.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
0.0030. One instance doing long work is the shape of a win.
3

Write the decision

printf 'decision=refused reason=overhead 3x work date=2026-10-10\n' > /tmp/d.txt; cat /tmp/d.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line with both numbers. A refusal with numbers is a decision that can be revisited.

Data Flow

A design to a refusal
1 The module is instantiated once
↓
2 The work is timed per call
↓
3 The crossing cost is timed per call
↓
4 The two numbers are compared and written
Why this works
Why the measure is per call

The cost is per call and the work is per call. Two numbers on the same axis are comparable.

The honest outcome

A design that is refused. The refusal is written with the two numbers, and the write-up is the deliverable.

Examples

Startup is per instance

Instantiating a module is work. A loop that instantiates per item pays that work per item.

Memory is reserved, not used

The module reserves a flat array. The reservation is the footprint whether or not it is touched.

The comparison is against the host

The question is not whether WASM runs. The question is whether it beats what runs natively.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Crossing the boundary
Previous Lesson
Crossing the boundary
Next Lesson
The host is a component
The host is a component →