Skip to content

ref(opt): compile out Clay's unused debug-tools UI#89

Draft
natemoo-re wants to merge 1 commit into
mainfrom
ref/clay-debug-tools
Draft

ref(opt): compile out Clay's unused debug-tools UI#89
natemoo-re wants to merge 1 commit into
mainfrom
ref/clay-debug-tools

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

Clay's built-in debug inspector ships in our wasm but clayterm never uses it. Clay__RenderDebugView (~700 lines + ~150 UI string literals) is reachable from the exported Clay_EndLayout behind a runtime if (context->debugModeEnabled) branch, so --gc-sections can't strip it, and at -O2 clang inlines it into the layout monolith (the "55 KB function" that dominated twiggy). clayterm never calls Clay_SetDebugModeEnabled, so it's pure dead weight.

  • Adds patches/clay-disable-debug-tools.patch: upstream-compatible #ifndef CLAY_DISABLE_DEBUG_TOOLS guards around the #pragma region DebugTools block and its single call site in Clay_EndLayout. The guards are harmless no-ops unless the flag is defined.
  • Makefile applies the patch to the clay submodule at build time (idempotent — skips if already applied; reverted by make clean) and opts in via -DCLAY_DISABLE_DEBUG_TOOLS.
  • raw wasm 155,934 → 111,234 bytes (−44,700, −28.7%)
  • brotli (what ships) 41,809 → 30,417 bytes (−11,392)
  • npm esm/wasm.js 53,143 → 38,903 bytes (−14,240, ≈ −13.9 KB unpacked) — wasm.js is the only changed package file
  • Cold path only: debugModeEnabled is always false at runtime, so no executed layout code changes — none of the -Oz perf tradeoff. deno task test passes (8 / 146 steps); watching CodSpeed to confirm neutrality.
  • Upstream opportunity: the region is already bracketed with #pragma region DebugTools / #pragma endregion, so this CLAY_DISABLE_DEBUG_TOOLS flag is a ~6-line PR to nicbarker/clay and would benefit every wasm Clay consumer. If accepted upstream, bump the submodule and drop the patch — only the -D flag remains.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 6, 2026

Open in StackBlitz

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

commit: d08642c

@natemoo-re natemoo-re marked this pull request as draft June 6, 2026 16:46
@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented Jun 6, 2026

Merging this PR will degrade performance by 13.64%

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 20 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation long input burst (200 bytes) 576.1 µs 1,264.5 µs -54.44%
Simulation dashboard layout 439.9 µs 591.1 µs -25.58%
Simulation printable ASCII (single char) 174.5 µs 91.9 µs +89.93%

Tip

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


Comparing ref/clay-debug-tools (d08642c) with main (48ff4bb)

Open in CodSpeed

Clay's debug inspector (Clay__RenderDebugView, ~700 lines + ~150 UI strings) is reachable from the exported Clay_EndLayout behind a runtime debugModeEnabled branch, so --gc-sections can't drop it; at -O2 clang inlines it into the layout monolith. clayterm never enables debug mode, so it's dead weight.

Adds an upstream-compatible CLAY_DISABLE_DEBUG_TOOLS guard (patches/clay-disable-debug-tools.patch) applied to the clay submodule at build time and opted in via -DCLAY_DISABLE_DEBUG_TOOLS.

raw wasm 155,934 -> 111,234 (-28.7%); brotli 41,809 -> 30,417; npm esm/wasm.js 53,143 -> 38,903 (-13.9 KB unpacked). Cold path only (debugModeEnabled always false at runtime); deno task test passes.
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