Frontmatter
| id | 8872 |
| title | Perf: Implement Reverse Component Map in ComponentManager |
| state | Closed |
| labels | aiperformancecore |
| assignees | tobiu |
| createdAt | Jan 24, 2026, 12:21 AM |
| updatedAt | Jan 24, 2026, 2:54 PM |
| githubUrl | https://github.com/neomjs/neo/issues/8872 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Jan 24, 2026, 2:54 PM |
Perf: Implement Reverse Component Map in ComponentManager
tobiu assigned to @tobiu on Jan 24, 2026, 2:53 PM

tobiu
Jan 24, 2026, 2:53 PM
Input from Gemini 3 Pro:
✦ I have implemented the Reverse Component Map optimization to address the performance bottleneck in
syncVnodeTree.Changes:
Neo.manager.Component:
- Added
childMap(Map<String, Set>) to track parent-child relationships. - Added
getDirectChildren(parentId)method for O(1) lookup.- Enhanced
register,unregister, and addedonParentIdChangeto maintain the map.- Optimized
unregisterwith safe destructuring and intent-driven JSDoc.
Neo.component.Abstract:
- Implemented
afterSetParentIdto notifyComponentManagerof changes.
Neo.mixin.VdomLifecycle:
- Updated
syncVnodeTreeto useComponentManager.getDirectChildren(me.id)instead of the O(N)find()method.Tests:
- Added
test/playwright/unit/vdom/ParentIdChange.spec.mjsto verifychildMapintegrity during lifecycle events (create, move, destroy).- Verified against
test/playwright/unit/vdom/HiddenChildren.spec.mjsto ensure no regressions in the original bug fix (#8868).The optimization reduces child lookup complexity from O(N) to O(1), ensuring scalability for large component trees.
tobiu closed this issue on Jan 24, 2026, 2:54 PM
Description: The fix for #8868 (unmounting missing children in
syncVnodeTree) introduced a potential performance bottleneck.syncVnodeTreenow callsComponentManager.find({parentId: me.id})on every VDOM update. Sincefinditerates all components (O(N)), this scales poorly with the number of components.Goal: Optimize child lookup to O(1) by maintaining a Reverse Map in
Neo.manager.Component.Proposed Implementation:
childMap(e.g.,Map<String, Set<String>>) toNeo.manager.Component.registerto add the component to its parent's set.unregisterto remove the component from its parent's set.afterSetParentId(viaonConfigChangeor similar, or overrideComponentlogic) to move the component between sets.parentIdis a reactive config onNeo.component.Base, we can leverage this.getDirectChildren(parentId)that returns the Set (or Array).VdomLifecycle.syncVnodeTreeto use this optimized method.Note: This optimization is critical for maintaining high performance in large applications.