Skip to content

fix: eliminate O(n) lag on rectangular selection in large tables#4899

Open
KrzysztofDusko wants to merge 1 commit into
tabulator-tables:masterfrom
KrzysztofDusko:master
Open

fix: eliminate O(n) lag on rectangular selection in large tables#4899
KrzysztofDusko wants to merge 1 commit into
tabulator-tables:masterfrom
KrzysztofDusko:master

Conversation

@KrzysztofDusko

@KrzysztofDusko KrzysztofDusko commented Jun 7, 2026

Copy link
Copy Markdown

Rectangular selection via mouse drag caused severe lag proportional to scroll position. At the bottom of a 50k-row table, each mousemove event triggered three O(n) operations making selection unusable.

Root causes and fixes:

  1. RowManager.getRowFromPosition() used .find() scanning from index 0, reaching O(n) for rows near the bottom. Replaced with O(1) direct array access displayRows[position - 1] with .find() fallback for grouped-row edge cases.

  2. SelectRange.getTableRows() created a new filtered array copy on every call. Added _tableRowsCache with invalidation in resetRanges() and tableDestroyed().

  3. handleCellMouseMove / handleColumnMouseMove had no throttling, causing the full layout pipeline (getActiveCell -> getCell x 2 per range -> range.layout) to execute on every mouse event (~120/sec). Wrapped in requestAnimationFrame to cap at one layout per frame.

…+ rows)

Rectangular selection via mouse drag caused severe lag proportional to
scroll position. At the bottom of a 50k-row table, each mousemove event
triggered three O(n) operations making selection unusable.

Root causes and fixes:

1. RowManager.getRowFromPosition() used .find() scanning from index 0,
   reaching O(n) for rows near the bottom. Replaced with O(1) direct
   array access displayRows[position - 1] with .find() fallback for
   grouped-row edge cases.

2. SelectRange.getTableRows() created a new filtered array copy on every
   call. Added _tableRowsCache with invalidation in resetRanges() and
   tableDestroyed().

3. handleCellMouseMove / handleColumnMouseMove had no throttling, causing
   the full layout pipeline (getActiveCell -> getCell x 2 per range ->
   range.layout) to execute on every mouse event (~120/sec). Wrapped in
   requestAnimationFrame to cap at one layout per frame.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
@KrzysztofDusko KrzysztofDusko changed the title fix: eliminate O(n) lag on rectangular selection in large tables (50k… fix: eliminate O(n) lag on rectangular selection in large tables Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant