Reactivity atoms (spike S1)
The writable Atom holds one raw Glimmer tag (createTag, consumeTag, dirtyTag from @glimmer/validator).
Context
- Spike: S1 in
docs/plan.md, section 11
TanStack Table v9 keeps each state slice in an atom from @tanstack/store. The engine gets
its atoms through TableReactivityBindings (createWritableAtom, createReadonlyAtom,
batch, untrack, schedule). Lattice must not depend on @tanstack/store (decision 5).
Lattice needs atoms on Glimmer tracking, so that templates and caches react to engine state.
The engine uses this atom surface:
get(),set(valueOrUpdater)andsubscribe(listener), which returns{ unsubscribe }.- A
compareoption. A write of an equal value must change nothing. createAtom(fn)for a derived atom andcreateAtom(value)for a writable atom.batch(fn). The tests require that a subscriber gets one call for a batch of writes.
The floor is ember-source >= 6.12. Version 6.12 has no standalone tracked(value). The plan
gives two options for the atom body: a @tracked field, or tracked(value) on 7.4 and later.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- The writable
Atomholds one raw Glimmer tag (createTag,consumeTag,dirtyTagfrom@glimmer/validator). It does not use a@trackedfield. A@trackedfield uses the same tag type, but it also keeps a per-object meta map. With prototype methods, the raw tag is about 10 times faster to make, uses half the heap, and reads 2 to 4 times faster (see "Evidence"). The shippedAtomhas bound methods (item 6), so its heap is near the heap of@tracked, but it stays faster to make and to read. The 6.12.0 build exports all the functions that the atom uses (checked on unpkg). The tests ran only on 7.3.1. Lattice needs notracked(value)and no 7.4 floor. derived(fn, { compare })is a Glimmer cache (createCache,getValue). Whencomparefinds the new value equal, the cache returns the old reference.untrackis the Glimmeruntrackfrom@glimmer/validator.- Glimmer tags only pull.
subscribeadds a small push path. After each write, each subscription reads its atom again inuntrack, and calls its listener when the value changed.batchholds these calls until the outermost batch ends. - The engine keeps the TanStack bindings seam.
emberReactivityBindings()(insrc/store-reactivity-bindings.ts) gives the engine Lattice atoms, withcreateOptionsStore: true. A derived atom that readstable.optionsthen recomputes when the options change. Atomhas bound methods (get,setandsubscribeare fields), because the engine passesatom.getwithout its object (createRenderPhaseSource). Bound methods cost about 220 bytes for each atom. The engine makes oneAtomfor each state slice, so this cost is small there.- The plan fix stays: one tag per row (
row.version), not one tag per cell. The row version (milestone M2) uses a raw tag with prototype methods, notAtom, to keep the heap low.
Code: packages/core/src/reactivity/atom.ts. Tests: packages/core/tests/reactivity/.
Consequences
- The engine runs headless in Node and in Vitest. Spike S1 needs no browser mode.
@glimmer/validatoris a module that ember-source provides (6.12.0 and 7.3.1 both exportcreateTag,consumeTag,dirtyTag,untrack,createCacheandgetValue). Lattice adds no dependency.- An external atom that a user gives in
options.atomsmust be a Lattice atom (or an object with the sameget,setandsubscribe). A@tanstack/storeatom does not invalidate Glimmer caches. - The cost of a subscription is one atom read for each write. Templates do not use subscriptions. They read atoms directly, so the push path is only for code outside Ember.
- The plan sketch in section 4.3 shows
@tracked value. This ADR replaces that sketch with the raw tag. The maintainer must agree to this change before it goes in the plan.
Confirmation
Evidence
Machine: Apple M4, Node 24.11.1, ember-source 7.3.1 (dev build). The test
packages/core/tests/reactivity/tagCost.test.ts makes the atoms, then reads all of them in
one Glimmer cache. It writes one atom and reads the cache again. Command:
LATTICE_S1_ROWS=100000 NODE_OPTIONS=--expose-gc pnpm vitest run packages/core/tests/reactivity/tagCost --silent=false.
Three atom bodies:
@tracked: a class with a@tracked valuefield and prototype methods.- raw tag: a class with a private Glimmer tag and prototype methods.
Atom: the Lattice atom, a raw tag with bound methods.
Run 1 (the machine had no other load):
| Atom body | Shape | Tags | Make | Heap | First read | Clean read | Read after 1 write |
|---|---|---|---|---|---|---|---|
@tracked |
1 tag per cell | 1,000,000 | 720 ms | +570 MB | 1416 ms | 0.06 ms | 1307 ms |
@tracked |
1 tag per row | 100,000 | 60 ms | +61 MB | 66 ms | 0.007 ms | 34 ms |
| raw tag | 1 tag per cell | 1,000,000 | 67 ms | +308 MB | 327 ms | 0.006 ms | 291 ms |
| raw tag | 1 tag per row | 100,000 | 7 ms | +42 MB | 17 ms | 0.006 ms | 17 ms |
Run 2 adds Atom. Other jobs used the machine at that time, so the times are 2 to 5 times
higher than run 1. Compare the rows of run 2 with each other only. The heap numbers do not
change with load.
| Atom body | Shape | Tags | Make | Heap | First read | Read after 1 write |
|---|---|---|---|---|---|---|
@tracked |
1 tag per cell | 1,000,000 | 2216 ms | +565 MB | 4870 ms | 1657 ms |
@tracked |
1 tag per row | 100,000 | 135 ms | +62 MB | 153 ms | 82 ms |
| raw tag | 1 tag per cell | 1,000,000 | 134 ms | +311 MB | 978 ms | 1092 ms |
| raw tag | 1 tag per row | 100,000 | 16 ms | +41 MB | 42 ms | 69 ms |
Atom |
1 tag per cell | 1,000,000 | 781 ms | +530 MB | 545 ms | 949 ms |
Atom |
1 tag per row | 100,000 | 8 ms | +63 MB | 35 ms | 34 ms |
What the numbers show:
- A clean read is O(1). The cache checks one combined tag.
- A read after a write is O(tags that the cache read). One tag per row cuts this cost by about 17 times in run 1 (raw tag: from 291 ms to 17 ms).
- 1M tags in one cache is too slow for one frame with all atom bodies. A virtual grid reads only the tags of the rows on screen, and the row model pipeline reads one atom for the whole data array. So no cache in Lattice reads all row tags.
- The raw tag is the best body for a large count of tags (half the heap of
@tracked, about 10 times faster to make). The bound methods ofAtomcost about 220 MB for 1M atoms.
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/0001-reactivity-atoms.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/0001-reactivity-atoms.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: Accepted (2026-12-01, by the maintainer). The plan, section 4.3, now uses raw tags. A CI job on ember-source 6.12 must check the tag APIs. |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0001-reactivity-atoms.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.