|
1 | 1 | CC = clang |
2 | 2 |
|
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) |
8 | 19 |
|
9 | 20 | LDFLAGS_COMMON = -Wl,--no-entry \ |
10 | 21 | -Wl,--import-memory \ |
@@ -54,10 +65,10 @@ all: layout.wasm input.wasm layout.wasm.ts input.wasm.ts |
54 | 65 | @echo "Built input.wasm ($$(wc -c < input.wasm) bytes raw, $$(gzip -c input.wasm | wc -c) bytes gzip)" |
55 | 66 |
|
56 | 67 | layout.wasm: $(DEPS) |
57 | | - $(CC) $(CFLAGS) $(LAYOUT_LDFLAGS) -o $@ src/module-layout.c |
| 68 | + $(CC) $(LAYOUT_CFLAGS) $(LAYOUT_LDFLAGS) -o $@ src/module-layout.c |
58 | 69 |
|
59 | 70 | 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 |
61 | 72 |
|
62 | 73 | layout.wasm.ts: layout.wasm |
63 | 74 | deno run --allow-read --allow-write tasks/bundle-wasm.ts layout.wasm layout.wasm.ts |
|
0 commit comments