Client formula engine: IronCalc (spike S5)
Keep IronCalc as the default engine (formula-ironcalc).
Context
- Spike: S5 (plan section 11). Code and output:
spikes/ironcalc/(not in the pnpm workspace). - Engine version: IronCalc 0.9.1 (tag
v0.9.1, commiteb9ca75), npm@ironcalc/wasm0.9.1 and@ironcalc/wasm-xlsx0.9.1.
Plan section 8.3 makes IronCalc the default FormulaEngine. It runs in a Web Worker on the client.
The research (section 5.1) calls IronCalc "very early". Spike S5 must check function coverage,
custom functions, WASM size, load time, recalc time, worker support and xlsx round trip.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- Keep IronCalc as the default engine (
formula-ironcalc). Pin it to 0.9.1. - Run it in a Web Worker. Use the npm
@ironcalc/wasmbuild. Load@ironcalc/wasm-xlsxonly for import and export. - Do not plan a Lattice function layer from formula.js. IronCalc has no host function API. Add missing functions upstream in Rust.
- Do not promise the "< 100 ms to paint" gate for 100k formulas. IronCalc recalcs every formula on each edit. Set the gate at 10k formula cells for 1.0, or get dirty-set recalc upstream first.
- The adapter reads the visible range again after each recalc. IronCalc does not return a list of
changed computed cells, so
apply()must make theCellChange[]itself.
We do not change the plan now. The maintainer must agree to items 3, 4 and 5 (CLAUDE.md rule).
Consequences
- One engine runs in the browser and on the server (see ADR 0007). The client build and the WASI build gave the same results on the shared fixture.
- Every edit costs a full recalc. A sheet with 100k formulas cannot meet the 100 ms gate. Lattice must either set a lower gate or help upstream add dirty-set recalc.
- Missing functions need Rust work upstream. This is slower than a JS function layer.
- The adapter must make
CellChange[]itself. It reads the visible range after each recalc. - The bundle cost is about 725 KB gzip for the worker. Load it on demand, only for sheets.
- Fallback if upstream does not accept fixes: HyperFormula (GPL, the app owns the license), or a fork of IronCalc pinned to 0.9.1.
Confirmation
Evidence
Run each command in spikes/ironcalc with volta run --node 24.11.1.
Q1: function coverage (npm run s5:coverage, output in results/coverage.md)
- IronCalc 0.9.1 has 497 built-in functions (
base/src/functions/mod.rs:1620). - The test list has 178 names. 110 names come from Exceljet, "101 Excel functions you should know" (https://exceljet.net/articles/101-excel-functions). 68 more come from the Microsoft function categories by our judgement (financial, statistics, math, text, dates, dynamic arrays).
- The probe writes
=NAME()into a cell.#NAME?means the parser does not know the name. - Exceljet list: 108 of 110 present (98.2 %). Full list: 176 of 178 (98.9 %).
- Missing:
AGGREGATEandGETPIVOTDATA. No function gave#N/IMPL. - "Present" means that the name is known. For correctness, see the corpus result under Q5: 99.81 % of 71,661 formula cells give the same value as Excel.
Q2: custom functions (results/custom-functions.md)
- No.
Functionis a closed enum (functions/mod.rs:29). Lookup is a fixed struct (:568). Dispatch is a hardmatch(:2313). There is no callback API in Rust or in JS. - A
LAMBDAin a defined name works as a formula-level user function:=DOUBLE(21)gives 42 (s5/workbook.test.mjs). It cannot call host code.
Q3: size, load and recalc
| Item | Value |
|---|---|
@ironcalc/wasm .wasm |
2,090,515 B raw, 725,318 B gzip -9 |
| JS glue | 70,311 B |
@ironcalc/wasm-xlsx .wasm |
2,546,925 B raw |
| Load in Node 24 (import, compile, instantiate) | 5.5 ms to 29 ms |
First new Model() |
19 ms to 108 ms |
The compile time in Node is low because V8 compiles WASM lazily. Measure it again in a browser worker in M0.
Workbook test (npm run s5:test, 4 tests pass): SUM, VLOOKUP, XLOOKUP, IF, DATE,
EDATE, NETWORKDAYS, TEXT, PMT, SUMPRODUCT, INDEX/MATCH, TEXTJOIN, LET, a
cross-sheet ref and a named range all give the Excel results. After one input change, the
dependents across sheets and names update.
Recalc of 100k formula cells after one input change (npm run s5:bench, results/bench-100k.txt):
| Shape | Run 1: dependent edit, median of 5 | Run 1: unrelated edit | Run 2: dependent edit, min of 11 |
|---|---|---|---|
Flat: =$A$1*2+C{r} |
100 ms | 69 ms | 101 ms |
Chain: =B{r-1}+C{r} |
64 ms | 64 ms | 733 ms |
10-cell SUM window |
213 ms | 135 ms | 131 ms |
- The host was an Apple M4 with 10 cores. Run 2 ran at load average 135, so its numbers are high. Run them again on a quiet machine in M0.
- An edit to a cell that no formula reads costs the same as a dependent edit. This agrees with
the source:
Model::evaluate"evaluates every formula in the workbook" (base/src/evaluation.rs:498-506). - These are engine times only. Worker messages and paint come after them. At 100k formulas the "< 100 ms to paint" gate fails.
- 100k
setUserInputcalls take 0.8 s to 8 s. AtoBytessnapshot of the same model is 1.87 MB and loads withfromBytesin 11 ms to 133 ms. Load sheets from snapshots, not cell by cell. - ID to A1 cost (plan 8.3): to tokenize 100k formulas with
getTokenstakes 0.7 s to 6.2 s under load. The adapter must convert only the formulas that change, not the full sheet. flushSendQueue()after one edit gives 25 bytes of user diffs (bitcode). It does not hold computed values.
Q4: Web Worker (s5/worker.test.mjs, passes)
- The engine loads and recalcs in a Node
worker_threadsworker.windowanddocumentareundefinedthere. - The JS glue uses no DOM API. It uses
Intl.DateTimeFormatfor time zones andWebAssembly. Both exist in a Web Worker.
Q5: xlsx (npm run s5:xlsx, results/xlsx.json, results/xlsx-openpyxl.txt)
- A new workbook with formulas, bold, a fill, a number format and a merge:
toXlsx(6,686 B), thenfromXlsx. No difference in content, value, style or merge. - openpyxl 3.1 reads the same file. All 7 checks pass: both formulas (
XLOOKUPas_xlfn.XLOOKUP), bold, fill, number format, mergeA6:C6and the cached value. - IronCalc's own corpus of 221 Excel-authored files (
xlsx/tests/calc_tests):- All 221 load. A round trip (
toXlsx, thenfromXlsx) keeps every formula, value, style and merge in all 221. - 71,661 non-volatile formula cells: Excel's cached value against IronCalc's value. 136 differ (99.81 % match). 125 differ only in the last digits (Bessel, statistics, IRR).
- 8 show
-0.00against0.00. 3 are real bugs:VALUE()parses 3 date texts to other dates or to#VALUE!(TEXT/T_VALUE_VALUETOTEXT.xlsx).
- All 221 load. A round trip (
- Limits: the corpus is IronCalc's own test set, so it favours IronCalc. The check reads columns 1 to 60 only. IronCalc does not model charts, comments, data validation or pivots. The test does not check them.
Other findings
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/0006-formula-engine-ironcalc.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/0006-formula-engine-ironcalc.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/0006-formula-engine-ironcalc.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.