LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-grace
createdAtNov 3, 2026, 6:04 AM
updatedAtNov 3, 2026, 6:52 AM
githubUrlhttps://github.com/neomjs/neo/issues/20212
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 3, 2026, 6:52 AM

TreeStore clear() and reloads are quadratic in the visible node count

Closed v13.4.0/archive-v13-4-0-chunk-3 bugaiperformancecoregrid
neo-opus-grace
neo-opus-grace commented on Nov 3, 2026, 6:04 AM

Context

Clearing a TreeStore takes time quadratic in its visible node count. Store#afterSetData() clears before it adds, so every data reload of a large flat or expanded tree pays the same cost.

Measured on dev 5dcacbe with a unit probe (Turbo Mode, Node, ms):

Case clear() / reload
TreeStore, 10,000 flat visible nodes 75
TreeStore, 20,000 flat visible nodes 639
TreeStore, 40,000 flat visible nodes 1,769
Store, 40,000 rows (control) 0
TreeStore, 50 × 800 collapsed, 50 visible (control) 1
TreeStore, 50 × 800 expanded, 40,050 visible 777
TreeStore, 40,000 flat, store.data = rows 1,532

The Problem

TreeStore#splice() runs two O(N) scans once per removed node:

  1. Step 1b decides visibility with me.indexOf(node) > -1. Collection#indexOf() is _items.indexOf(...), a scan of the projection.
  2. The removal reaches Collection#splice() as an array of items, whose per-item path runs items.splice(me.indexOfKey(key), 1): a scan plus a shift for each item. clear() arrives as the numeric form splice(0, count), and the override converts it to that array form (_items.slice(...)), so the Collection's one-pass numeric path is never taken.

Each scan is quadratic on its own. At 40,000 flat visible nodes, fixing only the first leaves clear() at 1,580 ms. Fixing only the second leaves 501 ms, still quadratic (52, 197, 501 ms at 10k, 20k, 40k). Fixing both gives 31 ms, and the reload drops from 1,532 to 85 ms.

The Architectural Reality

  • src/data/TreeStore.mjs clear() wipes #allRecordsMap and #childrenMap, then calls super.clear(). That reaches Collection#clear(), whose this.splice(0, this.count) dispatches back into the splice() override.
  • splice() step 1b: if (me.indexOf(node) > -1) visibleToRemove.push(node). Step 4: super.splice(insertIndex, visibleToRemove, visibleToAdd, silent).
  • The projection's key map, me.map, holds exactly the visible keys (#rebuildKeysAndCount() rebuilds it from _items), and Collection#splice() removes by key. map.has(key) therefore answers the same question in O(1).
  • Design authority: the TreeStore#addChild JSDoc, "Ingestion is already O(N) over a level, so a per-node key scan makes a bulk load O(N²) … in the one class whose whole premise is 50k-record ingestion."

The Fix

In TreeStore#splice():

  1. Step 1b: me.map.has(key) instead of me.indexOf(node) > -1.
  2. Step 4: when the call removes the whole projection (index === 0 && removeCountOrToRemoveArray === me.count), delegate the numeric form, super.splice(0, me.count, visibleToAdd, silent), so the Collection drops the projection in one pass.

Acceptance Criteria

  • AC-1: clear() on a TreeStore resolves no node position by scanning. A spec counts indexOf / indexOfKey calls during clear() of a flat and of an expanded tree and expects none; on dev it counts one or more per visible node.
  • AC-2: clear() and a data reload leave the state they leave on dev and fire the same mutate payload: count 0, nothing reachable through get() or getChildren(), and the removed items in projection order.
  • AC-3: The existing TreeStore specs and the unit tier pass.
  • AC-4: The PR body carries this table re-measured at its head commit.

Out of Scope

  • Bulk removal of a non-contiguous subset (store.remove(manyNodes)). The Collection's array removal stays per-item, here and for plain Stores; it gets its own ticket if measured to matter.
  • Step 2a's me.indexOf(parentNode) check when adding under an expanded parent, which is not on the clear path.

Related

  • TreeStore#addChild: the same class's bulk-load O(N²) fix, and the precedent for measuring at 20k+ nodes.
  • #9432: the clear() override against the split-brain leak. Its requirement that clear() calls super.clear() holds under this fix.
  • #9404: the Tree Grid epic. It is past the sub-issue cap, so this stays standalone.

Live latest-open + closed sweep: latest 20 open, plus open and closed searches for TreeStore, TreeStore clear and TreeStore performance quadratic, at 2026-11-03T05:02Z. The same-surface closed hit is #9432 (Out of Scope / Avoided Traps read); no equivalent. A2A claim sweep: last 30 messages, all read states, no claim on TreeStore. MC sweep: "TreeStore clear slow large expanded tree reload", 10 results, all from the March build of #9404, no prior decision on the cost of clearing. Own-assignment sweep: 3 open, none overlapping.

Origin Session ID: dc38fc1a-5a51-4588-94b5-5467b1860850 Retrieval Hint: "TreeStore clear quadratic visible nodes reload splice indexOf"

🖖 Grace (Claude Opus 5.5, Claude Code) · session dc38fc1a-5a51-4588-94b5-5467b1860850

tobiu referenced in commit 7e026ef - "fix(data): TreeStore clear() and reloads stay linear in the visible node count (#20212) (#20213)" on Nov 3, 2026, 6:52 AM
tobiu closed this issue on Nov 3, 2026, 6:52 AM