Skip to content

Commit c3b1605

Browse files
committed
docs(bench): the engine x thread matrix, and what each cell costs
Confirms the worker-thread hypothesis rather than leaving it as a card. 20k calls per cell, one process, same trivial export: JIT main thread 16547 ns JIT worker thread 1181 ns interp main thread 399 ns interp worker thread 413 ns The 14x JIT penalty is entirely the initial thread, so zwasm D-584 is dodgeable cljw-side. The interpreter is thread-indifferent, which is what a cached stack limit looks like. And the JIT is still 2.9x the interpreter on a worker thread, which is D-585 becoming visible now that D-584 has stopped swamping it. Engine and thread are independent levers; the engine one stays shape-dependent, since the JIT wins 15.5x on compute-in-wasm.
1 parent a149251 commit c3b1605

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎.dev/bench/ffi_boundary/README.md‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,32 @@ Do not re-derive this from the source. An earlier pass read the call graph, foun
3434
the cause. It is real (zwasm D-585) but sits in the ~1.2 us remainder. See hive
3535
memory 20260905010714-4c94602c.
3636

37-
Follow-ups: kanban [CLJW-WASM-ENGINE-DEFAULT], [CLJW-WASM-WORKER-THREAD].
37+
## The engine x thread matrix, measured 2026-09-05
38+
39+
`engine_thread_matrix.clj`, 20k calls per cell, same trivial `add` export, same
40+
process. Run it directly: `./zig-out/bin/cljw .dev/bench/ffi_boundary/engine_thread_matrix.clj`
41+
42+
cell ns/call
43+
JIT main thread 16547
44+
JIT worker thread 1181
45+
interp main thread 399
46+
interp worker thread 413
47+
48+
Three readings, and each names a different fix:
49+
50+
1. **The 14x JIT penalty is entirely the initial thread.** Nothing else differs
51+
between rows 1 and 2. This is D-584 and it is dodgeable without touching
52+
zwasm: run the invocation on any thread that is not the process's first one.
53+
`@(future ...)` already does it today, measured at 12.5x on a separate run.
54+
2. **The interpreter is thread-indifferent** (399 vs 413), which confirms it
55+
caches the stack limit rather than re-querying per call.
56+
3. **Even on a worker thread the JIT is 2.9x the interpreter** on a trivial
57+
callee. That residual is D-585, the per-call module re-parse, now visible
58+
because D-584 has stopped swamping it.
59+
60+
So the engine choice and the thread choice are independent levers, and the right
61+
engine still depends on call shape: the JIT wins 15.5x on compute-in-wasm
62+
(`bench/wasm_jit_vs_interp.sh`) and loses on crossing-heavy work at any thread.
63+
64+
Follow-ups: kanban [CLJW-WASM-ENGINE-DEFAULT], [CLJW-WASM-WORKER-THREAD],
65+
[CLJW-WASM-EXPORTSIG-CACHE].
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(def n 20000)
2+
(defn burn [m]
3+
(loop [i 0 acc 0] (if (< i n) (recur (inc i) (wasm/call m "add" i 1)) acc)))
4+
(defn ms [f] (let [t0 (System/nanoTime) _ (f) t1 (System/nanoTime)]
5+
(/ (double (- t1 t0)) 1000000.0)))
6+
(defn ns-per [f] (/ (* (ms f) 1e6) n))
7+
8+
(def jit (wasm/load "bench/wasm/ffi/add.wasm" {:engine :auto :fuel 0}))
9+
(def interp (wasm/load "bench/wasm/ffi/add.wasm" {:engine :interp :fuel 0}))
10+
11+
;; warm every path
12+
(burn jit) (burn interp) @(future (burn jit)) @(future (burn interp))
13+
14+
(println (format "%-22s %10s" "cell" "ns/call"))
15+
(println (format "%-22s %10.0f" "JIT main thread" (ns-per #(burn jit))))
16+
(println (format "%-22s %10.0f" "JIT worker thread" (ns-per #(deref (future (burn jit))))))
17+
(println (format "%-22s %10.0f" "interp main thread" (ns-per #(burn interp))))
18+
(println (format "%-22s %10.0f" "interp worker thread" (ns-per #(deref (future (burn interp))))))

0 commit comments

Comments
 (0)