Frontmatter
| id | 9320 |
| title | Optimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure |
| state | Closed |
| labels | enhancementai |
| assignees | tobiu |
| createdAt | Feb 26, 2026, 11:14 PM |
| updatedAt | Feb 26, 2026, 11:17 PM |
| githubUrl | https://github.com/neomjs/neo/issues/9320 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Feb 26, 2026, 11:17 PM |
Optimize VDom Lifecycle and TreeBuilder hot paths to reduce GC pressure
tobiu assigned to @tobiu on Feb 26, 2026, 11:16 PM

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:
src/manager/VDomUpdate.mjs: Replaced all usages of array.forEachandMap.prototype.forEachwithforandfor...ofloops, including heavily used iteration paths intriggerPostUpdates,registerInFlightUpdate, and callback execution.src/mixin/VdomLifecycle.mjs: Replaced.forEachloops insideexecuteVdomUpdate(Object.keys,Object.entries) andsyncVnodeTreewithfor...inand standardforloops.src/util/vdom/TreeBuilder.mjs: Refactored the core recursive#buildTreemethod to use a standardforloop instead ofnode[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
This ticket addresses GC pressure optimizations within the core VDOM management files:
src/manager/VDomUpdate.mjs,src/mixin/VdomLifecycle.mjs, andsrc/util/vdom/TreeBuilder.mjs.The VDOM update lifecycle naturally deals with recursive tree building, queueing, and callback execution. By converting standard
.forEacharray iterations andMap.prototype.forEachiterations toforloops,for...inloops, andfor...ofloops, we can avoid creating closures and temporary arrays during high-frequency update cycles.Changes:
src/manager/VDomUpdate.mjs: RefactoredforEachmethods used on Maps (item.children.forEach,this.descendantInFlightMap.forEach) intofor...ofloops (for (const [key, value] of map)). Replaced array.forEachcalls withforloops inexecutePromiseCallbacks,registerInFlightUpdate, andtriggerPostUpdates.src/mixin/VdomLifecycle.mjs: ReplacedObject.keys(updates).forEach,Object.entries(response.vnodes).forEach, and other array.forEachcalls (like insyncVnodeTreeandexecuteVdomUpdate) withfor...inor standardforloops.src/util/vdom/TreeBuilder.mjs: Convertednode[childKey].forEach(item => ...)to a standardforloop in the recursive#buildTreemethod to avoid closure allocations at every node depth.