The IronCalc WASI module: a CI artifact with a batch call
The shim is a Rust crate in wasm/ironcalc-wasi, not a spike.
Context
- Changes: ADR 0007, items 2 and 3 of its decision.
- Code:
wasm/ironcalc-wasi,ruby/lattice-grid/lib/lattice/grid/collab/iron_calc*.rb,python/lattice-grid/src/lattice_grid/collab/ironcalc.py.
ADR 0007 put one IronCalc module, built for wasm32-wasip1, in the Ruby and Python servers. The
module was the spike shim in spikes/ironcalc/wasi-shim. Its C ABI had no call to insert or
delete rows and columns, to rename a sheet, to read the cell type or to free a workbook. Thus the
Ruby and Python collab servers loaded the full doc into a new instance on each submit, with one
call for each cell. At 10,000 cells, one submit took 1.4 s in Python. The Ruby gem had a copy of
the .wasm file (3.6 MB) that nothing built again.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- The shim is a Rust crate in
wasm/ironcalc-wasi, not a spike. It usesironcalc_base0.9.1 from crates.io and pins Rust 1.90.0 inrust-toolchain.toml. The safe logic is insrc/book.rs, with Rust unit tests. Theic_*exports insrc/lib.rsare thin wrappers. - The
.wasmfile is not in git (.gitignore). Thewasmjob in.github/workflows/ci.ymlrunscargo testand builds the file. It caches the cargo registry andtarget/by the hash ofCargo.lock, and always builds, so a change insrc/never gives an old file. Theruby,pythonandpython-postgresjobs download the file and test with it. - The gem and the wheel include the file that CI builds:
- Gem:
wasm/ironcalc_wasi.wasmis inspec.files.gem buildstops with a clear message when the file is not there. Bundler also reads the gemspec, so onlygem buildchecks. - Wheel and sdist:
lattice_grid/collab/ironcalc.wasmgoes in through hatchartifacts.hatch_build.pystops a sdist or wheel build without the file. An editable install does not need it.
- Gem:
wasmtimestays a soft dependency: the Gemfiledevelopmentgroup for Ruby, thecollabextra for Python.LATTICE_IRONCALC_WASMstill overrides the path.- New exports:
ic_close,ic_insert_rows,ic_insert_cols,ic_delete_rows,ic_delete_cols,ic_rename_sheet,ic_remove_sheet,ic_cell_typeandic_apply_batch.ic_get_rawgivese:<code>for an error, so a host does not read the text"#N/A"as an error. ic_apply_batchtakes a JSON array of ops (set,insertRows,insertCols,deleteRows,deleteCols,addSheet,renameSheet,removeSheet,setName), evaluates one time and gives[[sheet, row, col, typed], ...]for each cell whose value changed. The module keeps the last value of each cell and moves these keys on insert, delete and sheet removal. Thus one submit is one call, and the reply holds only the changed cells.- The Ruby
IronCalcand the PythonIronCalcEnginekeep the workbook across submits. They port#applyofpackages/formula-ironcalc/src/engine.ts: their own row and column IDs, the range shrink on delete, and the real sheet names.applytakes only the ops, as the TypeScriptFormulaEnginedoes. After an engine error, the doc server loads the doc again. - Action Cable runs the commands of one connection on a pool of threads, so a message can run
before
subscribed, and a submit can run before the join that the client sent first.ChannelHandlerruns the messages of one channel one at a time under a lock. It holds the messages that arrive before the first join (100 at most) and sends them on after the join. The Python ASGI server reads the messages of one socket in order, andConnection.receivechains each message after the one before. It does not have the problem, and a test shows this.
Consequences
- A local run of the Ruby or Python collab tests needs the module first:
cargo build --release --target wasm32-wasip1inwasm/ironcalc-wasi. The test setup finds the file intarget/there. - A cold CI build of the crate takes some minutes. The cache makes the next builds fast.
- The release file is about 3.8 MB (the spike file was 3.6 MB).
- A client that sends messages and never joins gets no reply for its first 100 messages on Action
Cable. After that, the server rejects them with
not_joined. - Not done: the precompiled module cache of ADR 0007 item 3. Each process still compiles the module one time at first use (about 1 s).
Confirmation
Evidence
The benchmark is one setCell submit on a 1,000 × 10 doc (9,000 numbers and 1,000 SUM
range formulas), through the full doc server. It is the median of 10 submits after one warm-up.
The specs assert less than 250 ms, so a slow CI runner does not fail.
| Server | Before (load on each submit) | After (ic_apply_batch) |
|---|---|---|
| Ruby | 1,368 ms | 5 ms to 22 ms |
| Python | 3,910 ms | 4.5 ms |
The host had a high load during the "before" runs. A one-off check of structural submits on
the same doc (process CPU time, because the host load made wall time not useful) gave about
13 ms (Ruby) and 20 ms (Python) for one insertRows, and about 50 ms (Ruby) and 38 ms (Python)
for one deleteRows. In Ruby, about 20 ms of a delete is in the engine and about 13 ms is in
the doc model. Run the benchmarks:
cd ruby/lattice-grid && bundle exec rspec spec/lattice/grid/collab/doc_server_benchmark_spec.rb
cd python/lattice-grid && .venv/bin/pytest tests/test_collab_bench.py -s
The cross-implementation fixtures (ruby/lattice-grid/spec/fixtures/collab/collab.json and
python/lattice-grid/tests/fixtures/collab.json) pass with the new engines.
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/0020-ironcalc-wasi-module.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/0020-ironcalc-wasi-module.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-02 | Joe Gaudet | Status in the Markdown file: accepted (maintainer decisions, 2026-12-02) |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0020-ironcalc-wasi-module.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.