LearnNewsExamplesServices
Frontmatter
id8599
titleOptimize updateVtext to be non-destructive and O(1)
stateClosed
labels
enhancementaiperformance
assigneestobiu
createdAtJan 13, 2026, 3:14 PM
updatedAtJan 13, 2026, 3:16 PM
githubUrlhttps://github.com/neomjs/neo/issues/8599
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 13, 2026, 3:16 PM

Optimize updateVtext to be non-destructive and O(1)

Closed v11.21.0 enhancementaiperformance
tobiu
tobiu commented on Jan 13, 2026, 3:14 PM

Currently, Neo.main.DeltaUpdates.updateVtext updates virtual text nodes by rewriting the innerHTML of the parent element using a regex. This is:

  1. Destructive: It destroys the state (focus, input values, scroll) of all sibling nodes in the same parent.
  2. Slow: It forces a re-parse of the entire parent content (O(N)).

The goal is to re-implement updateVtext to:

  1. Locate the start comment node (<!-- id -->) using DomAccess.
  2. Update the nodeValue of the specific text node sibling directly.
  3. Avoid touching innerHTML entirely.
tobiu added the enhancement label on Jan 13, 2026, 3:14 PM
tobiu added the ai label on Jan 13, 2026, 3:14 PM
tobiu added the performance label on Jan 13, 2026, 3:14 PM
tobiu assigned to @tobiu on Jan 13, 2026, 3:15 PM
tobiu referenced in commit 3cf0c95 - "perf: Optimize updateVtext to use direct DOM manipulation (#8599) on Jan 13, 2026, 3:16 PM
tobiu
tobiu Jan 13, 2026, 3:16 PM

Input from Gemini 3 Pro:

✦ I have replaced the destructive innerHTML based implementation of updateVtext with a precise, non-destructive DOM manipulation approach.

Changes:

  1. Logic: Instead of parsing a regex over the entire parent's HTML, the code now searches the parent's childNodes for the specific comment node containing the VNode ID (<!-- id -->).
  2. Update: Once found, it directly updates the nodeValue of the immediate nextSibling (which is the Text Node).
  3. Impact:
    • Performance: Changed from O(N) (string parsing) to O(N) (DOM traversal) but with significantly lower constant factor and zero browser re-layout cost for siblings.
    • State: Sibling nodes no longer lose focus, selection, or input values because the parent's innerHTML is never touched.

Changes pushed to dev.

tobiu closed this issue on Jan 13, 2026, 3:16 PM