Skip to content

🧼 tune wasm opt levels per module (layout for speed, input for size)#47

Draft
natemoo-re wants to merge 3 commits into
ref/opt-splitfrom
ref/wasm-opt
Draft

🧼 tune wasm opt levels per module (layout for speed, input for size)#47
natemoo-re wants to merge 3 commits into
ref/opt-splitfrom
ref/wasm-opt

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

@natemoo-re natemoo-re commented May 28, 2026

Building on #37's layout/input split, this tunes each module's clang opt level independently instead of sharing one -O2.

The -Oz render regression is concentrated almost entirely in a single function: Clay_EndLayout is ~33% of the code section and the entire layout hot path. Under global -Oz, every CodSpeed regression was a render/layout benchmark (−17% to −36%); every input-parser benchmark was unchanged. #37's module boundary happens to fall along that same seam, so each side can be optimized for what it needs:

  • layout.wasm-Os — keeps the render path fast without the full -O2 size cost
  • input.wasm-Oz — opt-insensitive in the benchmarks, so optimize purely for size
  • levels are overridable (make LAYOUT_OPT=-O2) to A/B on CodSpeed

Artifact sizes (default -Os / -Oz):

module raw gzip
layout.wasm 102.5 kB 40.9 kB
input.wasm 9.0 kB 4.3 kB

No wasm-opt post-pass — it's a ~600 B no-op on already-optimized output, so this drops the extra build dependency that the previous -Oz approach needed.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 28, 2026

Open in StackBlitz

npm i https://pkg.pr.new/clayterm@47

commit: af4561f

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 28, 2026

Merging this PR will degrade performance by 21.95%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 6 regressed benchmarks
✅ 14 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation diff render (second frame) 655.4 µs 1,031.4 µs -36.46%
Simulation dashboard layout 408 µs 595.9 µs -31.53%
Simulation bordered box with corner radius 218.4 µs 266.4 µs -18.03%
Simulation simple text 179.7 µs 216.7 µs -17.1%
Simulation render with pointer hit testing 272.4 µs 316.6 µs -13.98%
Simulation long input burst (200 bytes) 980.1 µs 1,102.9 µs -11.13%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ref/wasm-opt (3d50b7c) with main (02754a2)

Open in CodSpeed

Split the shared -O2 CFLAGS into per-module levels. layout.wasm holds
Clay_EndLayout (~33% of the code and the entire render hot path), so it
is built -Os; input.wasm is opt-insensitive in the benchmarks, so it is
built -Oz. Levels are overridable (LAYOUT_OPT/INPUT_OPT) to A/B on CodSpeed.
@natemoo-re natemoo-re changed the base branch from main to ref/opt-split June 1, 2026 14:06
@natemoo-re natemoo-re changed the title 🧼 optimize wasm build with -Oz and wasm-opt 🧼 tune wasm opt levels per module (layout for speed, input for size) Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant