Skip to content

perf(grid): attach columns in linear time and cut per-scroll header and row work - #4426

Open
datlechin wants to merge 4 commits into
mainfrom
perf/grid-tabs
Open

datlechin wants to merge 4 commits into
mainfrom
perf/grid-tabs

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Perf audit 2026-11-22b, grid-tabs lane (findings 6 and 7: G1, G2, G3, G4a).

  • G1: pooled NSTableColumns get a plain NSCell as dataCell. The default text field cell tiled the table on every attach, so attaching n columns was O(n²): 203 frame changes for 200 columns, now at most 10.
  • G1: one header refresh per column pass. reconcileColumns leaves it to its callers, which refresh after the sort indicators.
  • G2: DataGridHeaderView.resetCursorRects adds divider rects for the columns on screen only, with AppKit's geometry and cursors. AppKit's pass added one for every column on every scroll step.
  • G3: isFlipped getters in the app are nonisolated, so the Swift 6 executor check no longer runs in every coordinate conversion. New SwiftLint rule flipped_view_getter_isolation keeps it.
  • G3: DataGridRowView.isOpaque is true while the row draws its own opaque background; an even row fills its stripe once.
  • G4a: the data tab's grid (DataTabGrid) applies a DataTabGridPresentation named by its tab. onChange ran the closure of the body from before a switch and wrote the incoming tab's configuration into the outgoing tab's model, which rebuilt that grid's columns again on return.
  • .claude/rules/data-grid.md: one line each for the header cursor rects, the data cell and the presentation.

Measurements

Release builds, base 9d0d481cf1 (build/TablePro.app) against this branch, interleaved, same harness (ui-responsiveness --quick). Medians, n in brackets. Other lanes were building: load1 median 37 (base) and 30 (branch), range 8 to 65. Instruction counts are the metric to read; main ms moves with load.

Benchmark Base Branch Change
tabcols.switch.to_wide500.procMinstr (500-column tab switch) 2,833 (12) 1,114 (12) -61%, plan target at most 1,700
tabcols.switch.to_wide500.mainMs 244 (12) 87 (12) -64%
tabcols.switch.to_cols7.procMinstr 522 (12) 473 (12) -9%
grid.scroll.wide500.procMinstr (8,000 px fling, 500 columns) 11,450 (8, 9,191 to 14,152) 6,478 (8, 5,501 to 6,740) -4,970 M, -43%
grid.scroll.wide500.mainMs 1,011 (8) 689 (8) -32%
grid.scroll.typical1M.procMinstr (7 columns) 3,481 (8) 3,479 (8) within noise
resize.typical1M.procMinstr / resize.wide500.procMinstr 318 / 357 (16) 320 / 282 (16) unchanged
tabs.lldb.reconcileColumns.perSwitch (20-tab ring) 2.0 1.0 G4a
tabs.switch.procMinstr 546 (5) 529 (5) -3%

Time Profiler, main-thread samples in a 10 s window around one fling:

Frame Base Branch
-[NSTableHeaderView resetCursorRects], wide fling 163 of 931 (17.5%) 3 of 1,077 in DataGridHeaderView.resetCursorRects (0.3%)
isFlipped getters, 7-column fling 4 of 902 0 of 1,093
-[NSTableRowView isOpaque], 7-column fling 9 of 902 0 of 1,093

Deliberately not fixed here

  • G3b (size the grid from what SwiftUI offers): gated out. Check C9, SwiftUI sizing a platform view under the 7-column fling: 0.7% (6 of 902 samples) on the base and 0.8% on the branch, under the 3% gate; no sample has a grid frame. The saved 22 Nov traces give 0.5% and 0.9%.
  • G4b (keep one grid controller across table tabs): its gate is quiet pass 2, which runs after this lane merges. tabs.lldb.gridInit.perSwitch is still 1.0.
  • GX1 (row numbers off): 2,816 against 3,479 M (-19%) and 553 against 621 ms on the 7-column fling, under the 25% bar for a one-view row number gutter. Measured at load 80, so it is a lead, not a verdict.
  • GX2 (8-bit row layers): declined (D13).
  • GX3 and GX4 (one layer per pane, responsive scrolling): not run. Each needs a throwaway Release build, and disk sat at 12 to 20 GB with two build slots shared by four lanes.
  • 6b (AppKit asks the delegate for every column of a new row): the wide fling is still 1.9x the narrow one in instructions (6,478 against 3,479 M), above the plan's 1.5x line, so the body table under a header table design stays open.
  • 7c (tab strip reveal) and 7d (Structure and back): no PR in the plan; checks C3 and C4 were not added to the suite. structure.open and structure.back are unchanged within noise.
  • The quiet pass 1 grid and tab steps were all aborted by peer builds, so there is no quiet before number; the base runs above stand in for it.

Test plan

  • DataGridHeaderCursorTests (new): rects and cursors equal a recording stock NSTableHeaderView at min width, at max width, fixed, hidden and with resizing off; 500 columns scrolled to the middle add the visible columns plus one.
  • DataGridPaneTests: mounting 200 columns resizes the table at most 10 times (203 with the default cell, checked by reverting it); a default sort direction change keeps the headings, tooltips and labels.
  • DataGridColumnMetadataTests: metadata that adds an accessory still reaches the header.
  • DataGridBodyChromeTests: row view opacity follows its drawing path; full alpha in both appearances over a translucent stripe and under a row tint; same pixels as the two-step fill, also over a stale table background and a translucent theme background.
  • DataTabGridPresentationTests (new): B's presentation leaves A's model alone; equal rules never repaint; a rules change repaints once; rules changed while hidden repaint on return; a hosted A to B to A switch keeps each model's configuration.
  • No existing test changed. 362 tests across the grid, tab, diagram and query plan suites pass locally; lint passes, and the new rule flags override var isFlipped and override internal var isFlipped.

@datlechin
datlechin marked this pull request as ready for review November 23, 2026 05:57
@datlechin
datlechin enabled auto-merge (squash) November 23, 2026 05:57

This branch has not been deployed

No deployments
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