Skip to content

Commit 79052b0

Browse files
committed
🙅 revert aggressive optimization experiments pending benchmark
Reverts three changes that need benchmarks before landing: - -Oz / wasm-opt - brotli+Z85 wasm compression - wcwidth.c rewrite
1 parent 3437804 commit 79052b0

8 files changed

Lines changed: 1107 additions & 240 deletions

File tree

.github/workflows/preview.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
with:
2222
deno-version: v2.x
2323

24-
- name: install binaryen
25-
run: sudo apt-get install -y binaryen
26-
2724
- name: build wasm
2825
run: make
2926

.github/workflows/publish.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
with:
2424
deno-version: v2.x
2525

26-
- name: install binaryen
27-
run: sudo apt-get install -y binaryen
28-
2926
- name: build wasm
3027
run: make
3128

@@ -52,9 +49,6 @@ jobs:
5249
with:
5350
deno-version: v2.x
5451

55-
- name: install binaryen
56-
run: sudo apt-get install -y binaryen
57-
5852
- name: build wasm
5953
run: make
6054

@@ -115,9 +109,6 @@ jobs:
115109
with:
116110
deno-version: v2.x
117111

118-
- name: install binaryen
119-
run: sudo apt-get install -y binaryen
120-
121112
- name: build wasm
122113
run: make
123114

.github/workflows/verify.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
- name: lint
3131
run: deno lint
3232

33-
- name: install binaryen
34-
run: sudo apt-get install -y binaryen
35-
3633
- name: build wasm
3734
run: make
3835

@@ -91,9 +88,6 @@ jobs:
9188
with:
9289
deno-version: v2.x
9390

94-
- name: install binaryen
95-
run: sudo apt-get install -y binaryen
96-
9791
- name: build wasm
9892
run: make
9993

@@ -122,9 +116,6 @@ jobs:
122116
with:
123117
node-version: 24
124118

125-
- name: install binaryen
126-
run: sudo apt-get install -y binaryen
127-
128119
- name: build wasm
129120
run: make
130121

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
CC = clang
2-
WASM_OPT ?= wasm-opt
32
TARGET = clayterm.wasm
43
SRC = src/module.c
54

6-
CFLAGS = --target=wasm32 -nostdlib -Oz \
5+
CFLAGS = --target=wasm32 -nostdlib -O2 \
76
-ffunction-sections -fdata-sections \
87
-mbulk-memory \
98
-DCLAY_IMPLEMENTATION -DCLAY_WASM \
@@ -49,7 +48,6 @@ DEPS = $(wildcard src/*.c src/*.h)
4948

5049
$(TARGET): $(DEPS)
5150
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC)
52-
$(WASM_OPT) -Oz --enable-bulk-memory -o $@ $@
5351

5452
wasm.ts: $(TARGET)
5553
deno run --allow-read --allow-write tasks/bundle-wasm.ts

deno.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"@sinclair/typebox": "npm:@sinclair/typebox@^0.34",
1616
"dnt": "jsr:@deno/dnt@0.42.3",
1717
"effection": "npm:effection@^4.0.2",
18-
"@std/encoding": "jsr:@std/encoding@1",
19-
"@types/node": "npm:@types/node@^22"
18+
"@std/encoding": "jsr:@std/encoding@1"
2019
},
2120
"exports": {
2221
".": "./mod.ts",
@@ -26,9 +25,6 @@
2625
"include": ["*.ts"],
2726
"exclude": ["!wasm.ts"]
2827
},
29-
"compilerOptions": {
30-
"types": ["@types/node"]
31-
},
3228
"fmt": {
3329
"exclude": ["clay", "build"]
3430
},

deno.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/wcwidth.c

Lines changed: 1098 additions & 162 deletions
Large diffs are not rendered by default.

tasks/bundle-wasm.ts

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,13 @@
1-
import { brotliCompressSync, constants } from "node:zlib";
2-
3-
const Z85 =
4-
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
5-
6-
function encodeZ85(data: Uint8Array): string {
7-
let padLen = (4 - (data.length % 4)) % 4;
8-
let src = data;
9-
if (padLen > 0) {
10-
src = new Uint8Array(data.length + padLen);
11-
src.set(data);
12-
}
13-
let out: string[] = [];
14-
for (let i = 0; i < src.length; i += 4) {
15-
let v = src[i] * 16777216 + src[i + 1] * 65536 + src[i + 2] * 256 +
16-
src[i + 3];
17-
out.push(
18-
Z85[Math.floor(v / 52200625)],
19-
Z85[Math.floor(v / 614125) % 85],
20-
Z85[Math.floor(v / 7225) % 85],
21-
Z85[Math.floor(v / 85) % 85],
22-
Z85[v % 85],
23-
);
24-
}
25-
return out.join("");
26-
}
1+
import { encodeBase64 } from "@std/encoding/base64";
272

283
const wasm = await Deno.readFile("clayterm.wasm");
4+
const base64 = encodeBase64(wasm);
295

30-
const compressed = new Uint8Array(brotliCompressSync(wasm, {
31-
params: {
32-
[constants.BROTLI_PARAM_QUALITY]: 11,
33-
[constants.BROTLI_PARAM_SIZE_HINT]: wasm.length,
34-
[constants.BROTLI_PARAM_LGWIN]: 24,
35-
},
36-
}));
37-
38-
const z85 = encodeZ85(compressed);
39-
40-
// Decoder uses division instead of >>> to avoid 32-bit truncation on values near 0xFFFFFFFF.
41-
const source = `import{brotliDecompressSync}from"node:zlib";
42-
const Z="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#";
43-
const T=new Uint8Array(128);for(let i=0;i<85;i++)T[Z.charCodeAt(i)]=i;
44-
function d(s:string,n:number){const b=new Uint8Array(n);let o=0;for(let i=0;i<s.length&&o<n;i+=5){const v=T[s.charCodeAt(i)]*52200625+T[s.charCodeAt(i+1)]*614125+T[s.charCodeAt(i+2)]*7225+T[s.charCodeAt(i+3)]*85+T[s.charCodeAt(i+4)];if(o<n)b[o++]=Math.floor(v/16777216);if(o<n)b[o++]=Math.floor(v/65536)%256;if(o<n)b[o++]=Math.floor(v/256)%256;if(o<n)b[o++]=v%256;}return b;}
45-
const compressed=d(${JSON.stringify(z85)},${compressed.byteLength});
46-
export const compiled=await WebAssembly.compile(brotliDecompressSync(compressed));
6+
const source = `const bin = atob("${base64}");
7+
const bytes = new Uint8Array(bin.length);
8+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
9+
export const compiled = await WebAssembly.compile(bytes);
4710
`;
4811

4912
await Deno.writeTextFile("wasm.ts", source);
50-
console.log(
51-
`wrote wasm.ts (${wasm.length}${compressed.byteLength} bytes compressed, ${z85.length} bytes z85, ${
52-
Math.round(z85.length / wasm.length * 100)
53-
}%)`,
54-
);
13+
console.log(`wrote wasm.ts (${wasm.length} bytes encoded)`);

0 commit comments

Comments
 (0)