LearnNewsExamplesConnect
Frontmatter
assigneesVerlintas
createdAtNov 13, 2026, 4:11 AM
updatedAtNov 13, 2026, 3:48 PM
githubUrlhttps://github.com/neomjs/neo/issues/20855
authorneo-fable-clio
commentsCount2
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined1
signals[]
blockedBy[]
blocking[]
closedAtNov 13, 2026, 3:48 PM

A record change scans the store once, and once per bound view

Closed v14.0.0/archive-v14-0-0-chunk-1 enhancementhelp wantedgood first issueaiperformancecoregrid
neo-fable-clio
neo-fable-clio commented on Nov 13, 2026, 4:11 AM

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

  1. 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.
  2. 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

  • The reproducer's "write near the end" stays within 2× of "write near the start" at 1,000,000 rows.
  • A listener that reads data.index gets the record's current index, also when an earlier listener of the same event re-sorted the store.
  • A spread copy of the event ({...data}) carries index as a value.
  • grid.Body repaints a changed mounted row and calls store.indexOf zero times for a record change. A change to the colspanField still rebuilds the view data.
  • Unit specs cover the three behaviors above. Run them with npm run test-unit -- <spec path>: the repository has separate Playwright configs for unit and e2e, and the plain npx playwright test picks neither.

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
// 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: #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

Verlintas
Verlintas Nov 13, 2026, 4:54 AM

I'd like to take this.

Plan: publish recordChange.index as an enumerable getter that computes the current index on read, and have grid.Body#onStoreRecordChange locate the changed record among its pooled rows instead of calling store.indexOf. Unit specs will cover the getter (direct read, spread copy, after an earlier listener re-sorts) and the grid repaint path (mounted vs unmounted, colspanField).

Transparency: prepared by an AI agent (OpenCode, DeepSeek V4.1 Flash) under human supervision; I'll review the generated code and include the disclosure in the PR.

  • 2026-11-13T03:55:04Z @github-actions assigned to @Verlintas

@github-actions - 2026-11-13T03:55:05Z

Thanks for claiming this, @Verlintas, and welcome! Assigned to you — you can start now.

Your claim reserves this issue for 3 days (any comment here resets the clock; we still merge the first approve-worthy PR if another lands first or a claim goes quiet).

An automatic reply. How claims work [QUARANTINED_URL: github.com]

Verlintas referenced in commit 5b18db3 - "fix(data): compute recordChange.index on read (#20855)" on Nov 13, 2026, 5:06 AM
Verlintas cross-referenced by PR #20858 on Nov 13, 2026, 5:06 AM
Verlintas referenced in commit 5d25558 - "fix(data): compute recordChange.index on read (#20855)" on Nov 13, 2026, 2:45 PM
Verlintas referenced in commit e4c1c21 - "test(data): pin on-read recordChange index against caching (#20855)" on Nov 13, 2026, 2:45 PM
tobiu referenced in commit 530f279 - "fix(data): compute recordChange.index on read (#20855) (#20858) on Nov 13, 2026, 3:48 PM
tobiu closed this issue on Nov 13, 2026, 3:48 PM