LearnNewsExamplesServices
Frontmatter
id9417
titleOptimize `TreeStore` Hot Paths (Performance)
stateClosed
labels
enhancementaiperformancecore
assigneestobiu
createdAtMar 9, 2026, 4:00 PM
updatedAtMar 9, 2026, 4:11 PM
githubUrlhttps://github.com/neomjs/neo/issues/9417
authortobiu
commentsCount1
parentIssue9404
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 9, 2026, 4:08 PM

Optimize TreeStore Hot Paths (Performance)

Closed v12.1.0 enhancementaiperformancecore
tobiu
tobiu commented on Mar 9, 2026, 4:00 PM

Goal

Maximize the performance of recursive and iteration-heavy operations inside Neo.data.TreeStore by replacing high-overhead functional iterators (Array.prototype.forEach) with optimized for loops.

Context

Tree structures naturally require recursive algorithms to collect descendants (e.g., collectVisibleDescendants). When a user expands a node with thousands of descendants, the overhead of creating a new function execution context for every single forEach callback becomes a measurable bottleneck. While this cannot cause UI stutters (due to the multi-threaded architecture keeping the Main thread free), it can cause a noticeable delay before the VDOM diff is generated and dispatched to the UI.

Acceptance Criteria

  • Refactor add(): Replace forEach on items and newRoots with for loops.
  • Refactor collectVisibleDescendants(): Replace forEach on children with a for loop. This is the most critical recursive hot path.
  • Refactor expand() and collapse(): Replace forEach on children and siblings with for loops.

Dependencies

  • Depends on the core TreeStore implementation.
tobiu added the enhancement label on Mar 9, 2026, 4:00 PM
tobiu added the ai label on Mar 9, 2026, 4:00 PM
tobiu added the performance label on Mar 9, 2026, 4:00 PM
tobiu added the core label on Mar 9, 2026, 4:00 PM
tobiu added parent issue #9404 on Mar 9, 2026, 4:00 PM
tobiu assigned to @tobiu on Mar 9, 2026, 4:02 PM
tobiu referenced in commit b04627c - "perf: Optimize TreeStore recursive hot paths (#9417) on Mar 9, 2026, 4:07 PM
tobiu
tobiu Mar 9, 2026, 4:07 PM

Input from Gemini 3.1 Pro:

✦ Replaced all Array.prototype.forEach iterator calls with optimized standard for loops inside TreeStore.mjs.

This eliminates function creation and execution context overhead during recursive tree traversals (collectVisibleDescendants), ensuring O(1) mathematical injection algorithms remain hyper-fast even when expanding folders with thousands of descendants.

Changes pushed to dev.

tobiu closed this issue on Mar 9, 2026, 4:08 PM