Architecture decision record · ADR-0019

Engine parity: column types, flex, auto-size, BigInt, group filter, pivot, calculated columns and the value cache

@ember-lattice/column-types has no dependency on @ember-lattice/core.

Status
Proposed
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

Plan sections 4.4 and 4.5 ask for built-in column types on Millwork codecs and real-enums, and for engine features that AG Grid has and TanStack does not: flex widths, auto-size, pivot, "show values as", calculated columns and a value cache. The parity matrix also lists a BigInt filter and a group filter. The maintainer was not available. This ADR records each decision.

All the new engine code is in Lattice files, not in ported files. PORT_MAP.md lists them under "Lattice files". Some ported type files got one new entry each. PORT_MAP.md records these changes too.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

1. Column types are a separate plain TypeScript package

@ember-lattice/column-types has no dependency on @ember-lattice/core. It uses structural types for the rows and the column def that it reads. Thus the package can also serve the servers and the export package later.

  • A ColumnType<T> has compare, format(value, locale), parse(text, locale), isValue, a default filter op set (filterOps), a default aggregation name and an optional exact sum.
  • The filter op names are the leaf ops of the Lattice protocol (eq, between, in and others). A typed filter value is { op, value }. A text operand is parsed first, so a floating filter can send the text that the user typed.
  • columnType(type, def) sets sortFn, filterFn, aggregationFn, sortUndefined: 'last' and meta.columnType. The values in def win.
  • Format and parse use Intl, with the locale as an argument. Number text such as 1.234,5 in de-DE reads as 1234.5.
  • Money, decimal and percent use the Millwork values. Their text keeps all the digits: the package formats the decimal text through the ES2023 Intl.NumberFormat, which takes a string. Node 22 has it. The package tsconfig adds the ES2023.Intl lib for this.
  • The money sum adds the bigint amounts at the largest scale. Mixed currencies give no sum. The decimal sum works the same way.
  • Millwork core has no date type. A date value is a Date, an epoch number or ISO text. ISO text with no zone is UTC, as in the protocol. A date shows in UTC, so the day does not move. A datetime shows in the runtime time zone.
  • An enum column sorts in the declaration order of values, shows label, and has a set filter (in, notIn) by default.
  • URL and email text reads through the Millwork codecs, so a javascript: URL does not read.
  • The engine sorts only undefined last in both directions. A null value sorts as the largest value, so a descending sort puts it first.

2. Flex widths and auto-size are functions, not state

flex is a new column def key (ColumnDef_ColumnSizing). applyFlexWidths(table, width) gives each visible flex column a share of the free width, and writes the result to the columnSizing state. A share outside minSize and maxSize is clamped, and the other flex columns split the rest again. The sizes are whole pixels that add up to the free width.

autoSizeColumns(table, measure, columnIds?) sets sizes from a callback. The grid measures the DOM; the engine has no DOM. The grid calls applyFlexWidths again when its width changes. An available-width atom in the engine would only copy a value that the grid has.

3. BigInt sort and filter functions

sortFn_bigint and filterFn_bigint* compare exactly past Number.MAX_SAFE_INTEGER. A bigint, an integer number and integer text convert to bigint. Other values never match.

4. The group filter is a filter function on key paths

filterFn_groupKeys takes a list of group key paths in the grouping order, for example [['US'], ['CA', 'Toronto']]. A leaf row passes when one path is a start of its own key path. The engine filters before it groups, so the grouped row model shows only the chosen groups.

5. Pivot: a Lattice feature with a table API, not a row model slot

columnPivotingFeature adds the columnPivoting state (enabled, by, values) and table.getPivotResult(). The result has the pivot columns, the rows, the column defs (a header group for each pivot key level, then a leaf for each value) and the column totals.

  • The result follows evaluate() in @ember-lattice/protocol: the same field names, the same key order (ascending, nulls last, text by UTF-16 code unit) and the same aggregates (count counts values that are not null). A parity test compares the two.
  • The source rows are the filtered rows in row model order. first and last use that order.
  • The result rows are the first group level, with $count. Deeper levels are in subRows. With no grouping, the result is one row, as in the protocol.
  • A new row model slot would change NonFeatureKeys and the slot checks of the port. A table API gives the same result with no change to them.
  • The feature is not in stockFeatures. A new LatticeFeatures interface gives TableFeatures its key.

6. "Show values as" is an option of a pivot value

A pivot value can have showAs: percentOfGrandTotal, percentOfRowTotal or percentOfColumnTotal. The cell shows its value divided by the same aggregate over all rows, over the rows of its row, or over the rows of its pivot column. The result is a fraction (0.25, not 25). A cell with no number, or a total of zero, shows null.

7. Calculated columns: a small parser, no eval

A column def with expression gets an accessor from calculatedColumnsFeature.

  • The parser runs once, when the column is made. It is a recursive-descent parser: numbers, text in double quotes, column ids ([id with spaces] for other ids), + - * /, the six comparisons, parentheses and IF, ROUND, ABS, MIN, MAX and CONCAT. It has a length limit and a depth limit. It never calls eval or Function.
  • A ref reads the accessor of the other column for the same row, so one calculated column can use another. The accessor gets no row, so a ref cannot call row.getValue.
  • Errors are ExpressionError values, never exceptions: #PARSE!, #NAME?, #REF!, #VALUE!, #DIV/0! and #CYCLE!. A set of the columns under evaluation finds a cycle.
  • A blank value is zero in arithmetic. ROUND rounds half away from zero.

8. The value cache: one entry for each row object

The core row model makes new rows when the data changes, and the per-row _valuesCache goes with them. valueCacheFeature keeps the accessor results in a WeakMap for each column, keyed by the row object. A new row object is a new row version, so only changed rows run their accessors again. This is the same rule as one tag for each row (ADR 0001).

  • table.invalidateRowValues(row?) forgets one row, or all rows, after a change in place.
  • The feature wraps the accessor with a property setter, so it also caches an accessor that a later feature sets, for example a calculated column. The feature order has no effect.
  • An accessor that reads the row index must not use the cache: the key is the row object.

9. The UI and editing parts of the engine features

  • Pivot in the grid. pivotView(table) in @ember-lattice/ui makes a second table from getPivotResult(), and the grid shows it through its public @table arg. A table for each result object: the engine gives the same object until its inputs change. The grid needs no pivot code.
  • "Show values as". A Values zone chip has a second select for showAs. The PivotState value columns carry it as a Lattice key, showAs, next to the AG Grid ColumnVO keys. No calculation leaves the key out.
  • Values aggregates on group rows. In and out of pivot mode, a group row (and the root total) aggregates a column in columnPivoting.values with the zone function, not the aggregationFn of the def. The functions are the protocol functions of pivot.ts, so a group row and a pivot cell agree. One definition for each function keeps the resolve cache of the column valid. Two ported files change: rowAggregationFeature.utils.ts reads the option through aggregationOption, and createGroupedRowModel.ts has the values as a memo dependency. A sum of a column with meta.columnType.sum (money, decimal) uses that exact sum.
  • Zone order. Alt+ArrowUp and Alt+ArrowDown on a zone chip move it. The chip is a focusable group, not a button, because it holds a select and a button. A select keeps its own keys.
  • Group keys. groupKeysFilter(table, columnId) keeps the source column filters and writes one value to a filterFn_groupKeys column: the distinct key paths of the core rows that pass, to the deepest filtered level. A list that keeps no row has a path with a key that no row has, because an empty list removes the filter.
  • BigInt filter. The protocol values have no bigint. The bigint filter kind writes the decimal text, and the UI filter function tests each BigInt leaf itself: it puts a boolean key in place of the leaf before the protocol matchesFilter runs. bigintType in the column types package reads integer text only: it checks the text before it calls BigInt().
  • Typed defaults. The UI and editing read meta.columnType structurally: they do not depend on @ember-lattice/column-types. The filter kind, the ops and the parse come from the type. A typed column edits only with meta.lattice.editable: true: a type alone does not make a column editable. ColumnType.values() gives the values of an enum for its select.

Measurements

The value cache test changes one row of 100,000, rebuilds the row model, and then times one read of two computed columns for each row: an accessor (price * qty) and a calculated column over it. The rebuild is the same with and without the cache, so it is not in the time. The numbers are the median of 5 runs. Other jobs gave the machine a high load (a load average of more than 100), so compare the two numbers of this run only.

Value cache Read time Accessor calls
No 1,397 ms 200,000
Yes 848 ms 1

The accessor count is exact and does not change with the load. The time that stays with the cache is the engine read path (row.getValue), not the accessors. The gain is larger when an accessor costs more. Run the measurement again with LATTICE_VALUE_CACHE_ROWS=100000 pnpm vitest run packages/core/tests/implementation/features/value-cache.

Consequences

  • Core now has three Lattice features: columnPivotingFeature, calculatedColumnsFeature and valueCacheFeature. They are not in stockFeatures.
  • Core has no @sindresorhus/is dependency, so the new core files use the same guards as the ported files. Add the dependency to core to change them.
  • The pivot has no UI yet. The side bar needs a pivot zone and a value zone.
  • The grid must call applyFlexWidths on resize and autoSizeColumns with its measure.

Confirmation

Not recorded in the original ADR.

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/0019-engine-parity.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/0019-engine-parity.md

Changelog

DateAuthorChange
2026-12-02Joe GaudetStatus in the Markdown file: proposed, 2026-12-02.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0019-engine-parity.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.