Skip to content

perf(grid): fast zero-allocation numeric stat formatting in GridSelectionCalcEngine #1531

Closed

Description

@ZhuchkaTriplesix

Problem

In GridSelectionCalcEngine.formatNum (lib/features/workspace/grid_selection_calc_engine.dart), whenever the user drags or modifies a selection in the data grid:
formatted.replaceAll(RegExp(r'0+$'), '').replaceAll(RegExp(r'\.$'), '')
is invoked for each summary metric (Sum, Avg, Min, Max).
This dynamically compiles two RegExp instances and runs two regex replacement passes on every pointer movement.

Solution

  • Trim trailing 0 and . characters using a zero-allocation backward index scan on code units (codeUnitAt).
  • Only perform a single substring slice when trailing characters actually exist.

Benefits

  • 0 RegExp compilations during continuous cell selection drag.
  • Zero GC churn in status bar summary updates.

Activity

  1. added this to the 0.5.0 milestone on Oct 12, 2026
  2. added
    data-gridInteractive data grid, cell editor, filtering, groupings
    coreCore library logic and services
    P2Medium priority / Parity & Refactoring
    on Oct 12, 2026
  3. added a commit that references this issue on Oct 15, 2026
  4. ZhuchkaTriplesix commented on Oct 25, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Fixed on dev by 42a0290: perf(grid): no regex in formatNum, no comma copy in selection stats. It reaches main with the next dev to main merge (closed after checking the code and its tests).

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

    P2Medium priority / Parity & RefactoringcoreCore library logic and servicesdata-gridInteractive data grid, cell editor, filtering, groupingsenhancementNew feature or requestperformanceTheme parser epic label: performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions