Skip to content

Commit 7d8f1a3

Browse files
committed
ref(opt): build input.wasm for size
layout.wasm must stay -O2: Clay_EndLayout is the render hot path and its speed on heavy layouts comes from -O2's inlining/unrolling. -Os/-Oz both regress dashboard/diff-render by 24-32% (CodSpeed), so size-optimizing it is a net loss. input.wasm is opt-insensitive in the benchmarks, so build it -Oz for a free size win. Levels stay overridable via LAYOUT_OPT/INPUT_OPT.
1 parent 8aad222 commit 7d8f1a3

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

Makefile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
CC = clang
22

3-
CFLAGS = --target=wasm32 -nostdlib -O2 \
4-
-ffunction-sections -fdata-sections \
5-
-mbulk-memory \
6-
-DCLAY_IMPLEMENTATION -DCLAY_WASM \
7-
-Isrc -I.
3+
# Per-module optimization levels. layout.wasm holds Clay_EndLayout (~33% of the
4+
# code and the entire render hot path); on heavy layouts its speed comes from the
5+
# inlining/unrolling that only -O2+ does — -Os/-Oz regress dashboard/diff-render
6+
# by 24-32%, so layout must stay -O2. input.wasm is the trie + input state machine,
7+
# whose benchmarks are insensitive to opt level, so it is built -Oz for size.
8+
# Override on the command line to A/B on CodSpeed, e.g. `make LAYOUT_OPT=-O3`.
9+
LAYOUT_OPT ?= -O2
10+
INPUT_OPT ?= -Oz
11+
12+
CFLAGS_BASE = --target=wasm32 -nostdlib \
13+
-ffunction-sections -fdata-sections \
14+
-mbulk-memory \
15+
-Isrc -I.
16+
17+
LAYOUT_CFLAGS = $(CFLAGS_BASE) $(LAYOUT_OPT) -DCLAY_IMPLEMENTATION -DCLAY_WASM
18+
INPUT_CFLAGS = $(CFLAGS_BASE) $(INPUT_OPT)
819

920
LDFLAGS_COMMON = -Wl,--no-entry \
1021
-Wl,--import-memory \
@@ -54,10 +65,10 @@ all: layout.wasm input.wasm layout.wasm.ts input.wasm.ts
5465
@echo "Built input.wasm ($$(wc -c < input.wasm) bytes raw, $$(gzip -c input.wasm | wc -c) bytes gzip)"
5566

5667
layout.wasm: $(DEPS)
57-
$(CC) $(CFLAGS) $(LAYOUT_LDFLAGS) -o $@ src/module-layout.c
68+
$(CC) $(LAYOUT_CFLAGS) $(LAYOUT_LDFLAGS) -o $@ src/module-layout.c
5869

5970
input.wasm: $(DEPS)
60-
$(CC) $(filter-out -DCLAY_IMPLEMENTATION -DCLAY_WASM, $(CFLAGS)) $(INPUT_LDFLAGS) -o $@ src/module-input.c
71+
$(CC) $(INPUT_CFLAGS) $(INPUT_LDFLAGS) -o $@ src/module-input.c
6172

6273
layout.wasm.ts: layout.wasm
6374
deno run --allow-read --allow-write tasks/bundle-wasm.ts layout.wasm layout.wasm.ts

0 commit comments

Comments
 (0)