Skip to content

perf(grid): eliminate eager List<String> allocation on every pointer-move during drag selection #1348

Closed

Description

@ZhuchkaTriplesix

Summary

In lib/features/workspace/grid/grid_pointer_selection.dart (lines 12–25, 142–154), during mouse-drag selection (_isDragSelecting), whenever the pointer moves and crosses a cell coordinate boundary:
_notifySelectionAndFocus() extracts all cell values in the selection bounding box:

final values = <String>[];
for (var r = minRow; r <= maxRow; r++) {
  final row = _sortedRows[r];
  for (var c = minCol; c <= maxCol; c++) {
    values.add(row[c].toString());
  }
}
widget.onSelectionChanged?.call(_selection, values);

For a 100-row × 10-column selection box, this allocates and populates a new 1,000-element List<String> on every pointer-move event (up to 60–120 times per second during dragging).
Meanwhile, ResultsTab already debounces selection calculations by 60 ms (_calcDebounceTimer). The intermediate lists allocated during active dragging are discarded immediately, causing unnecessary GC pressure and transient frame drops during gestures.

Proposed Solution

  1. Separate coordinate selection updates from value extraction:
    • Provide lightweight coordinate bounds in onSelectionChanged without eagerly extracting strings.
    • Defer string extraction until drag ends (pointer-up) or until the debounced calculation timer fires.
  2. Only query the selected cell string values when actually calculating stats or copying to clipboard.

Acceptance Criteria

  • Dragging selection across large cell ranges does not allocate intermediate List<String> objects on every pointer-move event.
  • Selection highlighting and live coordinate bounds update smoothly at 60/120 Hz.
  • Selection calc metrics in ResultsTab remain accurate and properly updated.

Activity

  1. added
    frontendTheme parser epic label: frontend
    performanceTheme parser epic label: performance
    data-gridInteractive data grid, cell editor, filtering, groupings
    P3Low priority / Polish & Enhancements
    on Oct 10, 2026
  2. ZhuchkaTriplesix commented on Oct 11, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Done in #1414 (merged into dev).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority / Polish & Enhancementsdata-gridInteractive data grid, cell editor, filtering, groupingsfrontendTheme parser epic label: frontendperformanceTheme parser epic label: performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions