Port wasm solver to C and add regression coverage#206
Port wasm solver to C and add regression coverage#206Soccera1 wants to merge 9 commits intotiagozip:mainfrom
Conversation
tiagozip
left a comment
There was a problem hiding this comment.
looks pretty good other than these three minor things! if you can move testing over to bun test and fix these i'll start benchmarking so it can be in prod
| fs.rmdirSync(browserOutDir); | ||
| } catch {} | ||
| console.log(`Building C wasm...`); | ||
| execSync(`make -C "${cSrcDir}" clean`, { stdio: "inherit" }); |
There was a problem hiding this comment.
also a nitpick but this should have recursive: true.
- Convert wasm test scripts to `bun test` - Rename test files to `.test.js` - Keep node and browser solver regression coverage
|
do you have any benchmarks you can publish? |
|
is this on web or node/bun? |
bun installed from npm |
do you have a web benchmark? |
|
I will create one |
📝 WalkthroughWalkthroughReplaces the Rust-based WASM solver with a C-based WASM implementation, adds a Makefile-driven C build, introduces a benchmark suite (Node + browser) comparing C vs Rust baselines, updates build/test flows to run C artifacts, and adjusts docs and tests to reflect the C solver. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Builder as Build Artifacts
participant Runner as Bench Runner (Node / Browser)
participant WASM_head as C-based WASM (head)
participant WASM_rust as Rust WASM (baseline)
participant UI as Console / Browser UI
Builder->>Builder: buildHead() (make, produce cap_wasm.wasm + loaders)
Builder->>Builder: buildRust() (checkout baseline, build rust wasm + loaders)
Runner->>WASM_head: init() / load solve_pow
Runner->>WASM_rust: init() / load solve_pow
Runner->>WASM_head: verifySolver(challengeCases)
WASM_head-->>Runner: verification result
Runner->>WASM_rust: verifySolver(challengeCases)
WASM_rust-->>Runner: verification result
Runner->>WASM_head: benchmarkSolver(iterations,warmup)
WASM_head-->>Runner: timings + checksum
Runner->>WASM_rust: benchmarkSolver(iterations,warmup)
WASM_rust-->>Runner: timings + checksum
Runner->>UI: compare checksums, compute speedup, print results
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Results are consistent with yours in the web benchmark I created. Not sure why. Maybe the web benchmark is not using AVX2 for my implementation whereas it is for the old one? |
|
I've found the issue. With node it's also slower. |



What changed
wasm/src/c/src/cap_wasm.c, including SHA-256 hashing, hex-prefix target parsing, nonce formatting, and wasm allocator shims.wasm/src/rustand updated the docs/package metadata to describe the solver as C-based WASM.wasm/src/c/test-regression.cjsbecame a fixed regression suite,wasm/test/node.jsnow asserts expected nonces for the full challenge set, andwasm/test/node_odd_difficulty.jsverifies the odd-length target case.wasm/build.jsso the build runs the regression suite.Commit breakdown
629ed2f: Port wasm from Rust to C978c1f5: Remove Rust codedee457e: Update testsThis was done as the rust implementation had many external dependencies, and rustc is very difficult to bootstrap. This version has no external dependencies; it can be compiled with -ffreestanding.
I have also done some unscientific testing and this is over 13% faster.
Summary by CodeRabbit
New Features
Documentation
Tests
Chores