---
id: 9400
title: 'Performance: O(1) Fast Paths for onScrollCapture getById Traversal'
state: CLOSED
labels:
  - enhancement
  - ai
  - architecture
  - performance
assignees:
  - tobiu
createdAt: '2026-03-08T21:16:40Z'
updatedAt: '2026-03-08T21:35:46Z'
githubUrl: 'https://github.com/neomjs/neo/issues/9400'
author: tobiu
commentsCount: 1
parentIssue: null
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-03-08T21:35:46Z'
---
# Performance: O(1) Fast Paths for onScrollCapture getById Traversal

**Problem:**
During continuous scrolling of a complex Grid, profiling reveals that `VDomUtil.getById` and `VNodeUtil.getById` consume a combined **~7.8% of the App Worker's total CPU time** (nearly 700ms in a 1-minute trace).

This overhead is generated by the generic `onScrollCapture` listeners in `src/component/Abstract.mjs` and `src/component/Base.mjs`. For every single scroll event, the framework naively dumps the event `target.id` into `getById(me.vnode, target.id)`, which forces a full recursive tree traversal, even if the node that is scrolling is the component's root node or its designated content wrapper.

**Proposed Solution:**
Introduce O(1) Fast Paths in `onScrollCapture` to check the most common scrolling targets before falling back to the expensive deep traversal:

1. **Root Node Check:** Does `target.id` equal `me.vnode.id`?
2. **Logical Root Check:** Does `target.id` equal `me.id`? (Essential for components using `getVdomRoot` wrappers, where the inner node receives `me.id`).
3. **Items Root Check:** Does `target.id` equal `me.getVdomItemsRoot().id`?

These three checks will short-circuit practically all internal grid and container scrolling events, completely eliminating the deep recursive `getById` penalty.

## Timeline

- 2026-03-08T21:16:40Z @tobiu added the `enhancement` label
- 2026-03-08T21:16:41Z @tobiu added the `ai` label
- 2026-03-08T21:16:41Z @tobiu added the `architecture` label
- 2026-03-08T21:16:41Z @tobiu added the `performance` label
- 2026-03-08T21:23:15Z @tobiu referenced in commit `116b8f9` - "perf: O(1) Fast Paths for onScrollCapture getById Traversal (#9400)"
- 2026-03-08T21:23:34Z @tobiu assigned to @tobiu
### @tobiu - 2026-03-08T21:23:43Z

**Input from Gemini 3.1 Pro:**

> ✦ **Task Completed:**
> 
> - Introduced `O(1)` fast paths into `onScrollCapture` in `src/component/Abstract.mjs` and `src/component/Base.mjs`.
> - The framework now checks `target.id === me.id`, `target.id === me.vnode.id`, and `target.id === me.getVnodeItemsRoot()?.id` before falling back to `VNodeUtil.getById`.
> - This eliminates the need to recursively crawl massive VDOM structures (like Grids) on every single scroll frame when the node scrolling is the component's main scroll wrapper.
> - This effectively reclaims the ~7.8% App Worker CPU overhead identified in the performance trace.

- 2026-03-08T21:25:29Z @tobiu referenced in commit `18444a9` - "docs: Add intent and performance notes to onScrollCapture fast paths (#9400)"
- 2026-03-08T21:35:46Z @tobiu closed this issue

