Skip to content

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

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

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

@natemoo-re natemoo-re commented Jun 6, 2026

Copy link
Copy Markdown
Member

Clay's built-in debug inspector is gated behind if (context->debugModeEnabled), but tty doesn't benefit from this code path at all.

This PR patches Clay to add a CLAY_DEBUG_MODE_ENABLED macro (defaults to 1), which allows us to strip out the unused code. Good candidate for an upstream PR!

Makefile has also been updated with a generic patch mechanism, with patches/*.patch applied in order against the latest upstream base.

Net result size is reduced by 18.8 KB (down to 100.0 KB unpacked)

@pkg-pr-new

pkg-pr-new Bot commented Jun 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tty@89

commit: 0a1e0a8

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

codspeed-hq Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 10 untouched benchmarks


Comparing ref/clay-debug-tools (0a1e0a8) with main (facb4f6)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown

Size Reduced — -18.8 KB

100.0 KB unpacked

Clay's debug inspector (Clay__RenderDebugView, ~700 lines + ~150 UI strings) is reachable from the exported Clay_EndLayout behind runtime debugModeEnabled branches, 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_DEBUG_MODE_ENABLED value macro (default 1; patches/clay-debug-mode-enabled.patch), named to match the runtime context->debugModeEnabled selector. Generated against the submodule's recorded commit (938967a) and covering all four debugModeEnabled sites; opted out via -DCLAY_DEBUG_MODE_ENABLED=0.

The Makefile now applies Clay patches generically: every patches/*.patch is applied (in sorted order) after resetting clay/clay.h to pristine, so the applied set always matches the directory exactly and future patches (e.g. #115's grow-minDimensions fix) need no per-patch Makefile wiring. Reverted by make clean. Drop individual patches as they ship upstream.

raw wasm 155,877 -> 101,208 (-35.1%); brotli 44,141 -> 29,133. Cold path only (debugModeEnabled always false at runtime); deno task test test/ passes (19 files, 227 steps).
@natemoo-re
natemoo-re force-pushed the ref/clay-debug-tools branch from fe0f62d to 0a1e0a8 Compare August 27, 2026 10:08
@natemoo-re
natemoo-re marked this pull request as ready for review August 27, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant