Server formula runtime: one IronCalc WASI module (spike S6)
The server packages run one IronCalc module built for wasm32-wasip1.
Context
- Spike: S6 (plan section 11). Code and output:
spikes/ironcalc/(not in the pnpm workspace). - Engine version:
ironcalc_base0.9.1 (tagv0.9.1, commiteb9ca75). - Changed by: ADR 0020. The shim is now the crate
wasm/ironcalc-wasi, with a batch call; CI builds the.wasm.
Plan section 8.4 makes the server authoritative. The server runs the formula engine after it
orders the ops. Plan section 8.3 wants the same engine on the client and the server, so that both
give the same results. IronCalc has Node and Python bindings but no Ruby binding. The plan of
record for S6: build IronCalc for WASI and run the same .wasm file in Ruby, Python and Node.
The fallback is a native gem (rb-sys and magnus), then a Node calc service.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- The server packages run one IronCalc module built for
wasm32-wasip1. Ruby uses thewasmtimegem. Python useswasmtimefrom PyPI. Node usesnode:wasi. - The module exports a small C ABI (
spikes/ironcalc/wasi-shim/src/lib.rs):ic_new,ic_add_sheet,ic_define_name,ic_set,ic_evaluate,ic_get,ic_get_raw,ic_alloc,ic_freeandic_last_error. Strings are UTF-8 (pointer and length). The real package will add snapshot load and save (toBytes/fromBytes) and a batch call. - The server packages ship a precompiled module cache (
Module#serialize) for each platform, or make it at first boot. A cold compile is too slow for each request. - The Ruby fallback (native gem with
rb-sysandmagnus) is not necessary. We did not build it.
Consequences
- One binary gives the same results in Node, Python and Ruby. The plan's S6 plan of record works. The native gem fallback is not necessary.
- The server packages own a small shim crate and its build. A CI job must build the
.wasmand run the three-host compare test on each IronCalc upgrade. - The server module is 3.6 MB. It is larger than the client build (2.1 MB), because it includes
chrono-tzandregex. This size is not a problem on a server. - Cold compile is 0.7 s to 12 s. Servers must cache the compiled module. Workers must keep one instance alive and not compile for each request.
- IronCalc recalcs every formula on each edit (ADR 0006). The server pays this cost on each op. For large sheets, the server must batch ops and evaluate once for each batch.
- The browser can run the npm build. The browser could also run this WASI module with a small WASI shim in JS. We did not test that.
Confirmation
Evidence
Commands (run in spikes/ironcalc):
volta run --node 24.11.1 npm run s6:build # cargo build --release --target wasm32-wasip1
volta run --node 24.11.1 npm run s6:node
volta run --node 24.11.1 npm run s6:python # .venv/bin/python -I s6/python_run.py
volta run --node 24.11.1 npm run s6:ruby # bundle exec ruby s6/ruby_run.rb
volta run --node 24.11.1 npm run s6:test # compare.test.mjs + client-build-compare.mjs
Build
ironcalc_base0.9.1 builds forwasm32-wasip1with no source change. The build needs Rust 1.85 or later (rand0.10). The spike pins Rust 1.90.0 inwasi-shim/rust-toolchain.toml.- The module is 3,587,246 B raw and 982,162 B gzip -9. It imports 6 WASI functions only:
clock_time_get,random_get,fd_write,environ_get,environ_sizes_getandproc_exit. It needs no file system and no network. - A release build takes about 2.5 minutes from clean.
Same results in three hosts (s6/compare.test.mjs, 2 tests pass)
The shared fixture is s6/fixture.json. It has two sheets, a named range, a LAMBDA name,
28 formula cells and 5,000 generated formula cells (SIN, EXP, SQRT, LN, NORM.S.DIST,
STDEV). It also has non-ASCII text with wildcards (COUNTIF "é*", MATCH "str*",
XLOOKUP "*CLAIR", SEARCH, UPPER("ß")), XIRR and a date-time TEXT.
| Host | Runtime | Load (compile and instantiate) | First evaluate |
|---|---|---|---|
| Node 24.11.1 | node:wasi |
12 ms to 78 ms | 23 ms to 37 ms |
| Python 3.12.9 | wasmtime-py 51.0.0 | 1,081 ms to 2,031 ms | 7 ms |
| Ruby 3.3.3 | wasmtime gem 50.0.0 | 704 ms to 2,262 ms | 4 ms to 23 ms |
- All three hosts give the same formatted values and the same raw
f64bits for every fixture cell, before and after an edit. - The SHA-256 of the 5,000 raw generated values is the same in all three hosts (
5ede92ae8cb6…). wasmtime 51 and wasmtime 50 gave the same bits. - The client build (npm
@ironcalc/wasm,wasm32-unknown-unknown) gives the same formatted values on the full fixture (s6/client-build-compare.mjs). This matters, because the two builds use different crates:regex-liteand JSIntltime zones on the client,regexandchrono-tzin WASI. The fixture tests only theUTCtime zone. - The ranges in the table come from two runs. The second run was at load average 135 on a 10-core Apple M4.
Server cold start (s6/ruby_cached_load.rb)
- Ruby, under load: compile 11,945 ms,
serialize114 ms (6,118,480 B),deserialize5.4 ms. A precompiled module removes the compile cost.
Environment notes
- The system Python (
/usr/bin/python3, Xcode 3.9.6) is killed (exit 137) when wasmtime instantiates any module, also an empty one. Homebrew Python 3.12 works. The venv uses it. - The
wasmtimegem 50.0.0 installs as a precompiledarm64-darwingem. No Rust is needed on the Ruby host.
Correctness found with the fixture (same in every build)
TEXT(DATE(2026,3,8)+TIME(2,30,0),"yyyy-mm-dd hh:mm")gives02:29. Excel gives02:30.UPPER("ß")givesSS. Excel givesß.
Interview record
Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.
| Question | Answer | Source |
|---|---|---|
| Where does the text of this page come from? | From the Markdown file docs/adr/0007-server-formula-runtime.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so. | Document: docs/adr/0007-server-formula-runtime.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: proposed |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0007-server-formula-runtime.md to this page. The text is the text of the Markdown file. |
The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.