LearnNewsExamplesServices
Frontmatter
id9319
titleOptimize Grid hot paths to reduce GC pressure
stateClosed
labels
enhancementai
assigneestobiu
createdAtFeb 26, 2026, 11:08 PM
updatedAtFeb 26, 2026, 11:13 PM
githubUrlhttps://github.com/neomjs/neo/issues/9319
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtFeb 26, 2026, 11:13 PM

Optimize Grid hot paths to reduce GC pressure

Closed v12.0.0 enhancementai
tobiu
tobiu commented on Feb 26, 2026, 11:08 PM

This ticket optimizes the hot paths within the buffered grid to reduce GC pressure and improve scrolling/rendering performance.

The Grid's virtual scrolling mechanism relies heavily on iterating over rows, columns, and cell components. Using .forEach() with inline arrow functions in these tight loops allocates arrays (like Object.values()) and closures repeatedly.

Changes:

  1. src/grid/Body.mjs: Replaced .forEach() loops with highly efficient for loops, particularly in hot paths like onStoreRecordChange, getColumnCells, and config setters that iterate over me.items.
  2. src/grid/Row.mjs: Replaced Object.values(me.components).forEach() with for...in loops to avoid intermediate array allocations and closures during component state updates and destruction. Refactored .forEach on oldCn to a standard for loop during cell VDOM recycling.
  3. src/grid/Container.mjs: Replaced .forEach in createColumns, bulkUpdateRecords, and removeSortingCss with for loops.

These optimizations are crucial for maintaining 60fps scrolling performance, especially when rapidly recycling rows with many cell components.

tobiu added the enhancement label on Feb 26, 2026, 11:08 PM
tobiu added the ai label on Feb 26, 2026, 11:08 PM
tobiu referenced in commit 457b7a9 - "perf: Optimize Grid hot paths to reduce GC pressure (#9319)" on Feb 26, 2026, 11:12 PM
tobiu assigned to @tobiu on Feb 26, 2026, 11:12 PM
tobiu
tobiu Feb 26, 2026, 11:12 PM

Input from Gemini 3.1 Pro:

✦ The grid hot path optimizations have been successfully implemented, and a syntax error (len is not defined) has been fixed. Changes have been pushed to dev.

Key changes:

  1. src/grid/Body.mjs: Replaced all .forEach() loops iterating over me.items with highly efficient standard for loops. This affects config setters, destroy(), getColumnCells, and onStoreRecordChange.
  2. src/grid/Row.mjs: Replaced Object.values(this.components).forEach() with for...in loops to avoid allocating arrays of values and closures during component state updates (afterSetMounted, afterSetTheme, updateCellComponents) and destruction. Refactored the .forEach on oldCn to a standard for loop in createVdom recycling.
  3. src/grid/Container.mjs: Converted .forEach iterations in bulkUpdateRecords, createColumns, and removeSortingCss to standard for loops.

These changes should significantly reduce GC pressure during rapid grid scrolling and rendering. Closing this ticket.

tobiu closed this issue on Feb 26, 2026, 11:13 PM