Sheet model, ID references and the IronCalc adapter (milestone M10, part 1)
@ember-lattice/formula (plain TypeScript): the FormulaEngine interface, the op and change types, A1 and R1C1 parsing, the stored ID form, and the shared conformance suite.
Context
Plan section 8 defines the sheet: a sparse cell model, refs by row and column ID, a
FormulaEngine seam, and IronCalc as the first engine (decision 21, ADR 0006). The sheet gate
in plan section 9 is "100k formula cells, one input change: < 300 ms in the worker, UI never
blocks; < 100 ms after upstream incremental recalc". Part 1 makes the model and the engine. It
does not make the Sheet surface or the collaboration layer.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
1. Three packages
@ember-lattice/formula(plain TypeScript): theFormulaEngineinterface, the op and change types, A1 and R1C1 parsing, the stored ID form, and the shared conformance suite.@ember-lattice/formula-ironcalc(plain TypeScript):IronCalcEngine, and a worker protocol (serveEnginein the worker,createWorkerEngineon the page).@ember-lattice/sheet(Ember addon): theWorkbookandSheetmodel, and number formats.
2. The stored reference form
The plan shows REF(COLUMN("c7"),ROW("r42")). That form has no field for the sheet and no field
for the $ flags. We use a compact Lattice form instead:
| A1 | Stored |
|---|---|
B2 |
{{c2,r2}} |
$B$2 |
{{$c2,$r2}} |
'My Sheet'!A1:B2 |
{{s2!c1,r1:c2,r2}} |
B:C |
{{c2,:c3,}} |
$2:3 |
{{,$r2:,r3}} |
{{cannot occur in an Excel formula outside a string, so the form is unambiguous.- The sheet part is the sheet ID. A sheet rename changes no stored formula.
- The
$flags stay, so the editor shows the same A1 text that the user typed. - IDs must match
[\w.-]+. Other IDs throw an error. - Names (named ranges,
LAMBDAnames) stay as names. - A ref to a deleted row, column or sheet prints as
#REF!. shrinkDeletedmoves a range end that a delete removes to the nearest row or column that stays in the range, as Excel does. The model and the IronCalc adapter both call it.
3. Ops
Each op is plain JSON and names rows, columns and sheets by ID, never by index. For example,
insertRows { ids, before }. A worker can take the ops, and the server OT (plan 8.4) can order
them. The model adds its own ops (setNote, freeze, addRule, addValidation and their
removes). The engine gets only the SheetOp part.
4. Values back from IronCalc
IronCalc 0.9.1 has no typed value getter. getFormattedCellValue applies the number format of
the cell: General shows 9 decimals, and a date formula shows 1/2/2026. The adapter gives each
input cell the format 0.00000000000000E+0 after the input. Then Number() reads the text.
- Lattice owns all display formats. IronCalc only computes, so this override has no effect on the display.
- Numbers come back with 15 significant digits, the same precision that Excel shows.
- A later IronCalc
toXlsxexport carries this format. XLSX export must write the Lattice formats instead.
5. Change lists
IronCalc recalculates the full workbook and gives no list of changed cells. The adapter reads
the watched cells again after each recalc and gives the values that changed. By default it
watches all cells with content. watch(ranges) limits the diff to the viewport and gives the
current values of the range (use it when the viewport moves).
6. Reactivity
Sheet keeps a slot (a core atom) for each cell that is read or written. A change to one cell
dirties only that slot. A read of an empty cell makes an empty slot, so the reader runs again
when a value appears there. The Cell record is replaced on each change, never mutated.
Consequences
- Refs stay valid when rows and columns move or sheets get a new name. The editor converts between A1 and the stored form at the edge.
- Large sheets must watch the viewport. The surface must call
watchwhen the viewport moves. - The model applies ops at once and sets computed values when the engine answers. This is the base for the optimistic client of plan 8.4.
- Remaining work: the
Sheetsurface, the collaboration layer (op log, rebase, presence), snapshot load, XLSX import and export, number-format fractions and locale codes.
Confirmation
Evidence
Sheet gate
Command: volta run --node 24.11.1 node packages/formula-ironcalc/tests/sheet-gate.ts (after the
build). It times the full worker round trip: post apply, recalc, diff, and receive the
changes. It also records the longest stall of the page thread (monitorEventLoopDelay) during
the edits. Node worker_threads, Apple M4, load average 12 to 20 (other jobs on the host). 7
runs for each row.
| Shape (100k formula cells) | Watched cells | Median | Min | Page stall | Changes |
|---|---|---|---|---|---|
Flat: B{r} = $A$1*2+C{r} |
Viewport 50 × 3 | 74 ms | 72 ms | 1.9 ms | 51 |
10-cell window: SUM(C{r-9}:C{r}) |
Viewport 50 × 3 | 108 ms | 100 ms | 4.7 ms | 51 |
| Flat | All 200,001 cells | 749 ms | 720 ms | 31 ms | 100,001 |
| 10-cell window | All 200,001 cells | 828 ms | 787 ms | 76 ms | 100,001 |
- With a viewport watch, the gate passes: < 300 ms in the worker, and the page thread stalls for less than 5 ms. An earlier run on a busier host gave 97 ms to 183 ms.
- With all cells watched, the gate fails (2.5× to 4× slow). The cost is the diff: 2 WASM calls for each cell, and a structured clone of 100k changes. The page stall of 76 ms is a long task (> 50 ms), so the UI blocks in this mode. Use the viewport watch for large sheets.
- The "< 100 ms after upstream incremental recalc" part is not possible on IronCalc 0.9.1: each edit recalculates every formula (ADR 0006).
- Load from a
SheetDoccell by cell took 3.9 s to 9.2 s for 200k cells. Load large sheets from a snapshot (toBytes/fromBytes) in a later part. - A conditional format formula rule and a formula validation each call
evaluate, so each costs one full recalc (about 100 ms at 100k formulas). The surface must batch or cache them.
IronCalc limits found
- No typed value getter (see decision 4). A 3-digit exponent prints wrong:
E+30300forE+300with the formatE+00. The adapter usesE+0. - A delete that removes a range end gives
SUM(A1:#REF!). Excel moves the end inward. The adapter sets the moved formula again after the delete. Named ranges do not get this fix yet. TEXTJOIN(",",TRUE,"a","","b")givesa,,b. Excel givesa,b. The conformance test lists this as a known failure, and fails when an upstream fix lands.- A formula such as
=DATE()gets its own number format on input. This replaces a column format, so the adapter sets the read format on each cell after the input. - No API lists the functions.
functions()gives the 174 names that spike S5 checked. - No evaluate API.
evaluate()writes the formula on a scratch sheet, reads it, and deletes the sheet. Each call costs one full recalc.
Tests
formula: 29 tests. Property tests (fast-check) check the A1 print and parse round trip, the A1 and R1C1 round trip, that scanner tokens join back to the input, and that stored refs under random inserts and deletes print the same A1 as an index oracle that uses Excel's shift and shrink rules.formula-ironcalc: 11 tests, with the 11-case conformance suite and a worker-thread test.sheet: 30 tests (11 number-format tests, 19 model tests).
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/0015-sheet-model.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/0015-sheet-model.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: proposed, 2026-12-01. |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0015-sheet-model.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.