Skip to content

Commit 42a9adc

Browse files
committed
Merge remote-tracking branch 'origin/main' into dart-flute-wasm-squash
2 parents 8ca78ab + 4352dab commit 42a9adc

17 files changed

+4015
-24
lines changed

Diff for: JetStreamDriver.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,20 @@ const BENCHMARKS = [
21622162
},
21632163
async: true,
21642164
testGroup: WasmGroup
2165-
})
2165+
}),
2166+
// zlib-wasm
2167+
new WasmEMCCBenchmark({
2168+
name: "zlib-wasm",
2169+
files: [
2170+
"./wasm/zlib/build/zlib.js",
2171+
"./wasm/zlib/benchmark.js",
2172+
],
2173+
preload: {
2174+
wasmBinary: "./wasm/zlib/build/zlib.wasm",
2175+
},
2176+
iterations: 40,
2177+
testGroup: WasmGroup
2178+
}),
21662179
];
21672180

21682181
// LuaJSFight tests

Diff for: wasm-cli.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ testList = [
3636
"argon2-wasm-simd",
3737
"8bitbench-wasm",
3838
"Dart-flute-wasm",
39+
"zlib-wasm",
3940
];
4041

4142
// Reuse the full CLI runner, just with the subset of Wasm line items above.

Diff for: wasm/richards/benchmark.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Benchmark {
99
await setupModule(Module);
1010

1111
// Set-up the problem (fill the work queue) on each run.
12-
Module._setup();
12+
const taskCount = 200_000;
13+
Module._setup(taskCount);
1314

1415
// Repeatedly call into Wasm to stress test JS-to-Wasm call performance.
1516
// I (dlehmann) suppose this wrapper was added (originally in JetStream 2)
@@ -21,7 +22,7 @@ class Benchmark {
2122
}
2223

2324
validate() {
24-
if (!Module._validate())
25+
if (Module._getQpktcount() !== 465212 || Module._getHoldcount() !== 186084)
2526
throw new Error("Bad richards result!");
2627
}
2728
}

Diff for: wasm/richards/build.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Built on 2025-01-29T18:38:57Z
1+
Built on 2025-02-10T17:28:11Z
22
Toolchain versions
33
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.73 (ac676d5e437525d15df5fd46bc2c208ec6d376a3)
44
Building...

Diff for: wasm/richards/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ emcc -o build/richards.js \
1515
-s WASM=1 -O2 -s TOTAL_MEMORY=83886080 \
1616
-g1 --emit-symbol-map \
1717
-s MODULARIZE=1 \
18-
-s EXPORT_NAME=setupModule -s EXPORTED_FUNCTIONS=_setup,_scheduleIter,_validate \
18+
-s EXPORT_NAME=setupModule -s EXPORTED_FUNCTIONS=_setup,_scheduleIter,_getQpktcount,_getHoldcount \
1919
richards.c | tee -a "$BUILD_LOG"
2020

2121
echo "Building done" | tee -a "$BUILD_LOG"

Diff for: wasm/richards/build/richards.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports["__wasm_call_ct
537537

538538
var _scheduleIter = Module["_scheduleIter"] = () => (_scheduleIter = Module["_scheduleIter"] = wasmExports["scheduleIter"])();
539539

540-
var _setup = Module["_setup"] = () => (_setup = Module["_setup"] = wasmExports["setup"])();
540+
var _setup = Module["_setup"] = a0 => (_setup = Module["_setup"] = wasmExports["setup"])(a0);
541541

542-
var _validate = Module["_validate"] = () => (_validate = Module["_validate"] = wasmExports["validate"])();
542+
var _getQpktcount = Module["_getQpktcount"] = () => (_getQpktcount = Module["_getQpktcount"] = wasmExports["getQpktcount"])();
543+
544+
var _getHoldcount = Module["_getHoldcount"] = () => (_getHoldcount = Module["_getHoldcount"] = wasmExports["getHoldcount"])();
543545

544546
var __emscripten_stack_restore = a0 => (__emscripten_stack_restore = wasmExports["_emscripten_stack_restore"])(a0);
545547

Diff for: wasm/richards/build/richards.js.symbols

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
5:handlerfn
77
6:devfn
88
7:setup
9-
8:validate
10-
9:emscripten_builtin_malloc
11-
10:sbrk
12-
11:_emscripten_stack_restore
13-
12:_emscripten_stack_alloc
14-
13:emscripten_stack_get_current
9+
8:getQpktcount
10+
9:getHoldcount
11+
10:emscripten_builtin_malloc
12+
11:sbrk
13+
12:_emscripten_stack_restore
14+
13:_emscripten_stack_alloc
15+
14:emscripten_stack_get_current

Diff for: wasm/richards/build/richards.wasm

12 Bytes
Binary file not shown.

Diff for: wasm/richards/richards.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// $ emcc -o richards.html -O2 -s TOTAL_MEMORY=83886080 -g1 -s "EXPORTED_FUNCTIONS=[_setup, _scheduleIter, _validate]" ./richards.c
1+
// $ emcc -o richards.html -O2 -s TOTAL_MEMORY=83886080 -g1 -s "EXPORTED_FUNCTIONS=[_setup, _scheduleIter, _getQpktcount, _getHoldcount]" ./richards.c
22

33
#include <emscripten.h>
44

@@ -15,12 +15,6 @@
1515
#include <stdio.h>
1616
#include <stdlib.h>
1717

18-
#if 1
19-
#define Count 200000
20-
#define Qpktcountval 465212
21-
#define Holdcountval 186084
22-
#endif
23-
2418
#define TRUE 1
2519
#define FALSE 0
2620
#define MAXINT 32767
@@ -335,11 +329,11 @@ void append(struct packet *pkt, struct packet *ptr)
335329
ptr->p_link = pkt;
336330
}
337331

338-
void setup()
332+
void setup(int count)
339333
{
340334
struct packet *wkq = 0;
341335

342-
createtask(I_IDLE, 0, wkq, S_RUN, idlefn, 1, Count);
336+
createtask(I_IDLE, 0, wkq, S_RUN, idlefn, 1, count);
343337

344338
wkq = pkt(0, 0, K_WORK);
345339
wkq = pkt(wkq, 0, K_WORK);
@@ -370,7 +364,12 @@ void setup()
370364
layout = 0;
371365
}
372366

373-
int validate()
367+
int getQpktcount()
368+
{
369+
return qpktcount;
370+
}
371+
372+
int getHoldcount()
374373
{
375-
return qpktcount == Qpktcountval && holdcount == Holdcountval;
374+
return holdcount;
376375
}

Diff for: wasm/zlib/benchmark.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
class Benchmark {
6+
async runIteration() {
7+
if (!Module._main)
8+
await setupModule(Module);
9+
10+
Module.FS.writeFile('input', Module.wasmBinary);
11+
12+
const inputStr = Module.stringToNewUTF8('input');
13+
const inputzStr = Module.stringToNewUTF8('input.z');
14+
const inputzoutStr = Module.stringToNewUTF8('input.z.out');
15+
16+
for (let i = 0; i < 10; i++) {
17+
Module._compressFile(inputStr, inputzStr);
18+
Module._decompressFile(inputzStr, inputzoutStr);
19+
if (Module.FS.stat('input').size !== Module.FS.stat('input.z.out').size) {
20+
throw new Error("Length after decompression doesn't match");
21+
}
22+
}
23+
24+
Module._free(inputzoutStr);
25+
Module._free(inputzStr);
26+
Module._free(inputStr);
27+
}
28+
29+
validate() {
30+
const input = Module.FS.readFile('input');
31+
const outputRoundtrip = Module.FS.readFile('input.z.out');
32+
for (let i = 0; i < input.length; i++) {
33+
if (input[i] !== outputRoundtrip[i]) {
34+
throw new Error("Content after decompression doesn't match at offset " + i);
35+
}
36+
}
37+
}
38+
}

Diff for: wasm/zlib/build.log

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Built on 2025-02-12T12:38:44Z
2+
Toolchain versions
3+
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.73 (ac676d5e437525d15df5fd46bc2c208ec6d376a3)
4+
Getting zpipe.c example source...
5+
Building...
6+
Building done

Diff for: wasm/zlib/build.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
rm -rf build/
6+
rm -f src/zpipe.c
7+
8+
touch build.log
9+
BUILD_LOG="$(realpath build.log)"
10+
echo "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | tee "$BUILD_LOG"
11+
12+
echo "Toolchain versions" | tee -a "$BUILD_LOG"
13+
emcc --version | head -n1 | tee -a "$BUILD_LOG"
14+
15+
echo "Getting zpipe.c example source..." | tee -a "$BUILD_LOG"
16+
curl -o "src/zpipe.c" https://www.zlib.net/zpipe.c
17+
18+
echo "Building..." | tee -a "$BUILD_LOG"
19+
mkdir build/
20+
emcc -o build/zlib.js \
21+
-s WASM=1 -O2 \
22+
-g1 --emit-symbol-map \
23+
-s USE_ZLIB=1 -s FORCE_FILESYSTEM=1 \
24+
-s MODULARIZE=1 -s EXPORT_NAME=setupModule -s EXPORTED_RUNTIME_METHODS=FS,stringToNewUTF8 -s EXPORTED_FUNCTIONS=_compressFile,_decompressFile,_free \
25+
src/zpipe.c src/main.c | tee -a "$BUILD_LOG"
26+
# If you want the native build for reference:
27+
# clang -o build/zlib -O2 -lz src/zpipe.c src/main.c
28+
29+
echo "Building done" | tee -a "$BUILD_LOG"
30+
ls -lth build/

0 commit comments

Comments
 (0)