LearnNewsExamplesServices
Frontmatter
id9320
titleOptimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure
stateClosed
labels
enhancementai
assigneestobiu
createdAtFeb 26, 2026, 11:14 PM
updatedAtFeb 26, 2026, 11:17 PM
githubUrlhttps://github.com/neomjs/neo/issues/9320
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtFeb 26, 2026, 11:17 PM

Optimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure

Closed v12.0.0 enhancementai
tobiu
tobiu commented on Feb 26, 2026, 11:14 PM

This ticket addresses GC pressure optimizations within the core VDOM management files: src/manager/VDomUpdate.mjs, src/mixin/VdomLifecycle.mjs, and src/util/vdom/TreeBuilder.mjs.

The VDOM update lifecycle naturally deals with recursive tree building, queueing, and callback execution. By converting standard .forEach array iterations and Map.prototype.forEach iterations to for loops, for...in loops, and for...of loops, we can avoid creating closures and temporary arrays during high-frequency update cycles.

Changes:

  1. src/manager/VDomUpdate.mjs: Refactored forEach methods used on Maps (item.children.forEach, this.descendantInFlightMap.forEach) into for...of loops (for (const [key, value] of map)). Replaced array .forEach calls with for loops in executePromiseCallbacks, registerInFlightUpdate, and triggerPostUpdates.
  2. src/mixin/VdomLifecycle.mjs: Replaced Object.keys(updates).forEach, Object.entries(response.vnodes).forEach, and other array .forEach calls (like in syncVnodeTree and executeVdomUpdate) with for...in or standard for loops.
  3. src/util/vdom/TreeBuilder.mjs: Converted node[childKey].forEach(item => ...) to a standard for loop in the recursive #buildTree method to avoid closure allocations at every node depth.
tobiu added the enhancement label on Feb 26, 2026, 11:14 PM
tobiu added the ai label on Feb 26, 2026, 11:14 PM
tobiu referenced in commit 9961615 - "perf: Optimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure (#9320)" on Feb 26, 2026, 11:16 PM
tobiu assigned to @tobiu on Feb 26, 2026, 11:16 PM
tobiu
tobiu Feb 26, 2026, 11:16 PM

Input from Gemini 3.1 Pro:

✦ The GC pressure optimizations in the VDOM lifecycle components have been successfully implemented and pushed to dev.

Key changes:

  1. src/manager/VDomUpdate.mjs: Replaced all usages of array .forEach and Map.prototype.forEach with for and for...of loops, including heavily used iteration paths in triggerPostUpdates, registerInFlightUpdate, and callback execution.
  2. src/mixin/VdomLifecycle.mjs: Replaced .forEach loops inside executeVdomUpdate (Object.keys, Object.entries) and syncVnodeTree with for...in and standard for loops.
  3. src/util/vdom/TreeBuilder.mjs: Refactored the core recursive #buildTree method to use a standard for loop instead of node[childKey].forEach(), eliminating closure overhead at every level of the recursive tree walk.

These optimizations will ensure that high-frequency VDOM update requests cause significantly less GC thrashing. Closing this ticket.

tobiu closed this issue on Feb 26, 2026, 11:17 PM