LearnNewsExamplesServices
Frontmatter
id9438
titleTreeStore: Reduce GC pressure and redundant iterations
stateClosed
labels
enhancementaiperformancegrid
assigneestobiu
createdAtMar 11, 2026, 11:09 AM
updatedAtMar 11, 2026, 11:14 AM
githubUrlhttps://github.com/neomjs/neo/issues/9438
authortobiu
commentsCount1
parentIssue9404
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtMar 11, 2026, 11:14 AM

TreeStore: Reduce GC pressure and redundant iterations

Closed v12.1.0/archive-v12-1-0-chunk-1 enhancementaiperformancegrid
tobiu
tobiu commented on Mar 11, 2026, 11:09 AM

Goal

Optimize TreeStore.mjs to minimize Garbage Collection (GC) pressure and avoid redundant operations, specifically targeting large dataset performance.

Context

During operations like filter, doSort, and bulk expands, the TreeStore can trigger thousands of array allocations and function invocations, significantly stressing the GC.

Acceptance Criteria

  • Refactor updateSiblingStats() to remove the .filter() array allocation, using a two-pass counter instead.
  • Hoist activeFilters calculation in filter() to avoid duplicate iteration.
  • Create a reusable private method #rebuildKeysAndCount() that pre-allocates the _keys array instead of using .map(). Use this method in doSort, filter, clearFilters, expandAll, and collapseAll.
  • Ensure all tests still pass.
tobiu
tobiu Mar 11, 2026, 11:13 AM

Input from Gemini 3.1 Pro:

✦ I have applied all the requested optimizations:

  1. Added #rebuildKeysAndCount() to pre-allocate the _keys array, eliminating the .map() overhead and array reallocations in clearFilters, collapseAll, doSort, expandAll, and filter.
  2. Hoisted the activeFilters array evaluation to the top of filter(), avoiding a duplicate iteration.
  3. Completely rewrote updateSiblingStats() to use a two-pass counting and indexing loop, eliminating the .filter() call that was previously creating thousands of short-lived arrays.

All unit tests pass successfully. The commit has been pushed. Closing this optimization sub-ticket.