Architecture decision record · ADR-0002

The adapter memoizes hydrate per record and field

The WarpDrive adapter wraps each codec Transformation in a memo: WeakMap<record, Map<field, { raw, value }>>.

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

getGenericField in @warp-drive/core reads the raw value from the cache and calls hydrate on each read. It does not use createMemo or a cache. So for a codec that gives an object, record.total === record.total is false. This breaks identity checks in templates and in code.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

  • The WarpDrive adapter wraps each codec Transformation in a memo: WeakMap<record, Map<field, { raw, value }>>.
  • The memo gives the stored value when the raw value is the same reference (===). Otherwise it calls hydrate again and stores the new pair.
  • hydrate gets (raw, options, record) and not the field name. So the Millwork field helper (valueField) puts the field name in options.field.

Consequences

  • The raw value reference in the cache is stable between reads, for getAttr and for getRemoteAttr. So === on the raw value is enough. A deep compare is not necessary.
  • A push with equal JSON gives a new raw reference, so the memo hydrates again and gives a new (equal) value. If this is a problem, the memo can also compare with the codec equals and keep the old value. M2 decides this.
  • The immutable record and the editable copy (checkout) are two objects. Each has its own memo entries, so each shows its own state.
  • The memo holds the record weakly, so it does not keep an unloaded record in memory.
  • The (record, field) key does not work for kind: 'array'. WarpDrive calls hydrate(rawItem, options, record) with no index, so all elements share one slot. A read of [0], [1], [0] gives a new value each time. A memo keyed by the raw element object (WeakMap<raw, value>) keeps element identity. A primitive raw element has no such key. M2 must choose the key for primitive elements (open item).

Confirmation

Evidence

  • packages/warp-drive/tests/spikes/s3-memo.test.ts
  • The no-op signal hooks in packages/warp-drive/tests/spikes/-store.ts do not change this result: getGenericField does not call createMemo.

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.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0002-memo-cache.md at commit c8154b0. 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/0002-memo-cache.md

Changelog

DateAuthorChange
2026-12-01Joe GaudetStatus in the Markdown file: Accepted (M0, spike S3).
2026-12-01Joe GaudetCommit 0a16254: Build Millwork 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0002-memo-cache.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.