agents/skills/wasm-d8-perf/SKILL.md
Reproduce, profile, and analyze Wasm performance using the V8 developer shell
(d8).
release build (e.g., out/x64.release/d8)
for benchmarking.optdebug (e.g., out/x64.optdebug/d8) for disassembling/debugging
(preserves symbols).console.time()).
/usr/bin/time -v (Wall time, memory) and
perf stat -d (cycles, instructions, IPC, branch misses).
perf fails due to permissions (e.g.
kernel.perf_event_paranoid), notify the user to adjust settings or
switch to a PMU-enabled environment (gLinux/Cloudtop). Fall back to
d8 --prof if needed.--trace-gc to trace garbage collection pauses,
especially if WasmGC is used.d8 --liftoff-only script.jsd8 --no-liftoff script.js
--no-liftoff disables speculative inlining since it skips
Liftoff execution and thus doesn't collect feedback.Find where time is spent, what the hottest functions, loops, blocks, or instructions are, so we focus on that:
./tools/profiling/linux-perf-d8.py to get a profile with
JIT symbols resolved, then analyze with perf report.d8 --prof script.js and analyze v8.log with
./tools/linux-tick-processor.d8 --trace-wasm-compilation-times and d8 --turbo-stats-wasm.wami (tools/dev/gm.py x64.release wami) and
disassemble: out/x64.release/wami --single-wat=<func_index> <path_to_wasm>Unoptimized Wasm binary patterns can hurt V8 compilation and execution.
-O3/-Os).Perform deep dives on hot functions:
d8 --trace-turbo --trace-turbo-filter=<func_name>.
jq
programmatically:
jq '.phases[].name' turbo-*.jsonjq '.phases[] | {name: .name, node_count: (if (.data | type) == "object" and .data.nodes then (.data.nodes | length) else 0 end)}' turbo-*.jsonjq '.phases[] | select(.name == "TurboshaftTypeAssertionsPhase") | select((.data | type) == "object" and .data.nodes) | .data.nodes[] | select(.title | contains("BoundsCheck"))' turbo-*.jsonperf annotate -i file.perf.data.jitted --stdio
to map hot instructions to bytecode.
out/x64.optdebug/d8 --print-wasm-code-function-index=<idx> --code-comments.
> disasm.txt) to avoid
flooding the terminal.--trace-wasm-inlining, --trace-turbo-inlining--wasm-loop-peeling,
--wasm-loop-unrolling to see an effect of those optimizations.--turboshaft-trace-load-elimination,
--turboshaft-trace-peeling, --turboshaft-trace-unrolling--trace-wasm-typer--wasm-tiering-budget=<value>.--wasm-inlining-budget=<value>.d8 --help | grep -i <keyword> or by looking up definitions in
src/flags/flag-definitions.h and via grep. Refer to v8-commands skill
for general usage.Provide a clear report summarizing:
Only proceed to this step after your initial report and explicit approval by the user.
--no-wasm-loop-unrolling, --no-turboshaft-wasm-load-elimination,
--no-wasm-inlining, --no-turbo-inline-js-wasm-calls).
wasm-opt -O3 (or -Os) if
available on PATH, or ask the user to rebuild with different flags.