Skip to content

Optimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure #9320

@tobiu

Description

@tobiu

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions