Context
A field write on a record publishes recordChange. What that costs grows with the record's position in the store, and again with every view bound to it. Measured on dev @ 70b443e524, node 25.9.0, a flat Neo.data.Store with lazy records (the reproducer is at the end):
| Rows |
Write near the start |
Write near the end |
The same with one listener that calls store.indexOf(record) |
| 100,000 |
4.1 µs |
16.8 µs |
31.9 µs |
| 1,000,000 |
4.1 µs |
138.6 µs |
277.3 µs |
On a Neo.data.TreeStore of 999,880 expanded rows, moving 913 records in one edit cost 130 ms in publication alone, before any view repeated the scan.
The Problem
Store#onRecordChange adds index: this.indexOf(data.record) to every event (src/data/Store.mjs:1663). indexOf is _items.indexOf(...) (src/collection/Base.mjs:1200): a scan of the visible rows, paid by every write, whether or not a listener reads the index.
Most listeners do not read it. They look the record up again:
grid.Body#onStoreRecordChange takes {fields, record} and calls me.store.indexOf(record) to test the mounted range (src/grid/Body.mjs:1612),
table.Body (src/table/Body.mjs:796), list.Base (src/list/Base.mjs:986) and list.Buffered (src/list/Buffered.mjs:743) do the same.
The lists do it on purpose: the event's index is taken before any listener runs, so a listener that re-sorts the store leaves it stale for the listeners after it (#20106). So one write costs one scan in the store and one more per bound view, and the index the store paid for can still be wrong.
A grid mounts a few dozen rows. Whether the changed record is among them does not depend on how many rows the store holds.
The Architectural Reality
Design authority: the JSDoc of Store#onRecordChange: "Reapplies opted-in local filters and sorters before publishing the record's settled index." The index stays part of the event. This ticket changes when it is computed.
- The event fires in one place (
src/data/Store.mjs:1661), after the optional refilter and resort.
RecordFactory.applyPreparedFields publishes each record of a batch through the same method, so a batch of n records costs n scans.
- A grid row holds its record (
record in src/grid/Row.mjs:65), and the body keeps its pooled rows in items.
The Fix
Store#onRecordChange: publish index as an enumerable getter on the event object that answers the record's current index when it is read. A listener that does not read it pays nothing, and one that reads it after an earlier listener re-sorted gets the current position.
grid.Body#onStoreRecordChange: find the changed record among the pooled rows (row.record === record) and repaint that row, without asking the store for an index.
Contract Ledger
| Target surface |
Source of authority |
Proposed behavior |
Fallback |
Docs |
Evidence |
recordChange event, index |
Store#onRecordChange, src/data/Store.mjs:1634-1665 |
The record's index at the moment a listener reads it; enumerable, so a spread copy carries a plain value |
none |
the method's JSDoc |
a unit spec reads index directly, in a spread copy, and after an earlier listener re-sorted |
grid.Body#onStoreRecordChange |
src/grid/Body.mjs:1609-1629 |
Repaints the pooled row that holds the record |
none |
the method's JSDoc |
a unit spec: a change to a mounted record repaints its row; a change to an unmounted one calls store.indexOf zero times |
Decision Record impact
none
Acceptance Criteria
Out of Scope
- The other listeners that scan (
table.Body, list.Base, list.Buffered, menu.List). Same pattern; each can follow in its own change once the event's index is cheap.
- The first
get(key) of a lazy row, which scans in Store#hydrateRecord (src/data/Store.mjs:1063), and the cost of adding one row to a large TreeStore.
- A position index inside
collection.Base.
Avoided Traps
- A
Map from item to index in the collection. Every splice, sort and filter invalidates it, and rebuilding it for a million rows costs more than the scans it saves in a store that changes often.
- A getter that keeps its first answer. A later listener would read a stale index after a re-sort: the defect
#20106 fixed in the lists.
- Dropping
index from the event. Listeners outside this repository may read it.
Related
#20106 (closed): the lists read the record's current index because the event's was stale. Its Out of Scope left the event's contract as it was; this ticket is that contract.
- #20848: a record field's setter converts its value twice. The same write path, a different cost.
Reproducer: record-change-scan.mjs
import path from 'node:path';
import {pathToFileURL} from 'node:url';
globalThis.Neo = {config: {environment: 'development', unitTestMode: true}};
const load = async file => (await import(pathToFileURL(path.resolve(file)).href)).default;
const Neo = await load('src/Neo.mjs');
await load('src/core/_export.mjs');
await load('src/manager/Instance.mjs');
const Store = await load('src/data/Store.mjs'),
rows = Number(process.argv[2] || 1_000_000),
store = Neo.create(Store, {
autoInitRecords: false,
model : {fields: [{name: 'id', type: 'Integer'}, {name: 'value', type: 'Integer'}]},
data : Array.from({length: rows}, (_, i) => ({id: i, value: 0}))
});
store.on('recordChange', () => {});
function write(from) {
const records = Array.from({length: 200}, (_, i) => store.getAt(from + i)), started = performance.now();
for (const record of records) record.value++;
return ((performance.now() - started) * 1000 / 200).toFixed(1)
}
console.log(`${rows} rows, one recordChange listener`);
console.log(`write near the start: ${write(0)} us`);
console.log(`write near the end: ${write(rows - 200)} us`);
store.on('recordChange', ({record}) => store.indexOf(record));
console.log(`write near the end, with a listener that calls store.indexOf(record): ${write(rows - 200)} us`); unowned-rationale: Ready for a contributor; maintainers provide planning and review.
Live latest-open + closed sweep: checked the latest 20 open issues and two closed searches (recordChange indexOf; record change index scan store performance) at 2026-11-13T03:10Z. One closed hit on this surface, #20106, read whole: its Out of Scope left the event's contract untouched, which is what this ticket changes. No equivalent open ticket. Backlog band: 33 open, orange; no owning ticket or epic exists for the store's publication cost. A2A claim sweep (the last 30 lane claims): none on this scope. Memory Core rationale sweep (record change publication, a scan per changed record): no prior decision. Own assignments (3 open): none on this surface. Knowledge Base ticket query: #9076 gave the store an internalIdMap for the same class of scan on another lookup.
Retrieval Hint: "recordChange indexOf scan store size grid body pooled row current index"
Origin Session ID: eae061dd-e957-4a68-a226-6e53f60707c4
📜 Clio · @neo-fable-clio · Claude Fable 5.2 · Claude Code · session eae061dd-e957-4a68-a226-6e53f60707c4
Context
A field write on a record publishes
recordChange. What that costs grows with the record's position in the store, and again with every view bound to it. Measured ondev@70b443e524, node 25.9.0, a flatNeo.data.Storewith lazy records (the reproducer is at the end):store.indexOf(record)On a
Neo.data.TreeStoreof 999,880 expanded rows, moving 913 records in one edit cost 130 ms in publication alone, before any view repeated the scan.The Problem
Store#onRecordChangeaddsindex: this.indexOf(data.record)to every event (src/data/Store.mjs:1663).indexOfis_items.indexOf(...)(src/collection/Base.mjs:1200): a scan of the visible rows, paid by every write, whether or not a listener reads the index.Most listeners do not read it. They look the record up again:
grid.Body#onStoreRecordChangetakes{fields, record}and callsme.store.indexOf(record)to test the mounted range (src/grid/Body.mjs:1612),table.Body(src/table/Body.mjs:796),list.Base(src/list/Base.mjs:986) andlist.Buffered(src/list/Buffered.mjs:743) do the same.The lists do it on purpose: the event's index is taken before any listener runs, so a listener that re-sorts the store leaves it stale for the listeners after it (
#20106). So one write costs one scan in the store and one more per bound view, and the index the store paid for can still be wrong.A grid mounts a few dozen rows. Whether the changed record is among them does not depend on how many rows the store holds.
The Architectural Reality
Design authority:the JSDoc ofStore#onRecordChange: "Reapplies opted-in local filters and sorters before publishing the record's settled index." The index stays part of the event. This ticket changes when it is computed.src/data/Store.mjs:1661), after the optional refilter and resort.RecordFactory.applyPreparedFieldspublishes each record of a batch through the same method, so a batch of n records costs n scans.recordinsrc/grid/Row.mjs:65), and the body keeps its pooled rows initems.The Fix
Store#onRecordChange: publishindexas an enumerable getter on the event object that answers the record's current index when it is read. A listener that does not read it pays nothing, and one that reads it after an earlier listener re-sorted gets the current position.grid.Body#onStoreRecordChange: find the changed record among the pooled rows (row.record === record) and repaint that row, without asking the store for an index.Contract Ledger
recordChangeevent,indexStore#onRecordChange,src/data/Store.mjs:1634-1665indexdirectly, in a spread copy, and after an earlier listener re-sortedgrid.Body#onStoreRecordChangesrc/grid/Body.mjs:1609-1629store.indexOfzero timesDecision Record impact
none
Acceptance Criteria
data.indexgets the record's current index, also when an earlier listener of the same event re-sorted the store.{...data}) carriesindexas a value.grid.Bodyrepaints a changed mounted row and callsstore.indexOfzero times for a record change. A change to thecolspanFieldstill rebuilds the view data.npm run test-unit -- <spec path>: the repository has separate Playwright configs for unit and e2e, and the plainnpx playwright testpicks neither.Out of Scope
table.Body,list.Base,list.Buffered,menu.List). Same pattern; each can follow in its own change once the event's index is cheap.get(key)of a lazy row, which scans inStore#hydrateRecord(src/data/Store.mjs:1063), and the cost of adding one row to a largeTreeStore.collection.Base.Avoided Traps
Mapfrom item to index in the collection. Every splice, sort and filter invalidates it, and rebuilding it for a million rows costs more than the scans it saves in a store that changes often.#20106fixed in the lists.indexfrom the event. Listeners outside this repository may read it.Related
#20106(closed): the lists read the record's current index because the event's was stale. Its Out of Scope left the event's contract as it was; this ticket is that contract.Reproducer: record-change-scan.mjs
// Run from the repository root: node path/to/record-change-scan.mjs [rows] import path from 'node:path'; import {pathToFileURL} from 'node:url'; globalThis.Neo = {config: {environment: 'development', unitTestMode: true}}; const load = async file => (await import(pathToFileURL(path.resolve(file)).href)).default; const Neo = await load('src/Neo.mjs'); await load('src/core/_export.mjs'); await load('src/manager/Instance.mjs'); const Store = await load('src/data/Store.mjs'), rows = Number(process.argv[2] || 1_000_000), store = Neo.create(Store, { autoInitRecords: false, model : {fields: [{name: 'id', type: 'Integer'}, {name: 'value', type: 'Integer'}]}, data : Array.from({length: rows}, (_, i) => ({id: i, value: 0})) }); store.on('recordChange', () => {}); /** Microseconds per `record.value++` over 200 records starting at `from`. */ function write(from) { const records = Array.from({length: 200}, (_, i) => store.getAt(from + i)), started = performance.now(); for (const record of records) record.value++; return ((performance.now() - started) * 1000 / 200).toFixed(1) } console.log(`${rows} rows, one recordChange listener`); console.log(`write near the start: ${write(0)} us`); console.log(`write near the end: ${write(rows - 200)} us`); // a bound list, table or grid body looks the record's row up again in its own handler store.on('recordChange', ({record}) => store.indexOf(record)); console.log(`write near the end, with a listener that calls store.indexOf(record): ${write(rows - 200)} us`);unowned-rationale: Ready for a contributor; maintainers provide planning and review.
Live latest-open + closed sweep: checked the latest 20 open issues and two closed searches (
recordChange indexOf;record change index scan store performance) at 2026-11-13T03:10Z. One closed hit on this surface,#20106, read whole: its Out of Scope left the event's contract untouched, which is what this ticket changes. No equivalent open ticket. Backlog band: 33 open, orange; no owning ticket or epic exists for the store's publication cost. A2A claim sweep (the last 30 lane claims): none on this scope. Memory Core rationale sweep (record change publication, a scan per changed record): no prior decision. Own assignments (3 open): none on this surface. Knowledge Base ticket query:#9076gave the store aninternalIdMapfor the same class of scan on another lookup.Retrieval Hint: "recordChange indexOf scan store size grid body pooled row current index" Origin Session ID: eae061dd-e957-4a68-a226-6e53f60707c4
📜 Clio · @neo-fable-clio · Claude Fable 5.2 · Claude Code · session eae061dd-e957-4a68-a226-6e53f60707c4