Repository navigation
Description
Problem
Opening a 1M-row PostgreSQL table from the sidebar takes 228-275 ms to the screen. The database is not the cost: the app's own trace (TABLEPRO_TABLE_LOAD_TRACE=1) shows the driver fetch at 4.6-14.9 ms and the grid reload at 2.4-3.8 ms.
Time Profiler over 10 open-and-close cycles from a sidebar click: 1,669 ms of main-thread CPU, about 167 ms per cycle.
- SwiftUI graph updates: 45% (756 ms). App frames under it:
ResultStatusBar.body34 ms,ReadoutZoneLayout19 ms,DataGridRepresentable.makeNSViewController14 ms,MainContentView.body10 ms. Most of it has no app frame: SwiftUI diffing the tab's view tree. - Core Animation commit, layout: 30% (498 ms), mostly
NSHostingViewlayout. - Core Animation commit, display: 10% (171 ms), of which
DataGridRowView.drawBackground53 ms and the header 9 ms. - Drawing the grid itself: about 5 ms per open.
- Toolbar validation and
SettingsSlice.value.getter: 22-25 ms per 10 cycles.
So about 75% of the open is SwiftUI building and laying out the tab around the grid, not the grid.
Cause
A table tab is a SwiftUI tree inside a hosting controller that is rebuilt and re-laid out on every pass.
MainEditorContentView.editorAreaContentwraps every tab kind except the query tab inAnyView(apple/TablePro/Views/Main/Child/MainEditorContentView.swift:166-172).EditorAreaController.showhosts it in anNSHostingController<AnyView>and assignsrootViewagain on everyapply(apple/TablePro/Views/Main/Child/EditorAreaController.swift:122-130). The query tab already left this path:QueryTabSplitControlleris AppKit down to its panes (EditorAreaController.swift:31-66, from perf(editor): build the query tab in AppKit and read the sidebar listing when the filter takes focus #3834).resultsSectionbuilds aVStackof the result-set bar, error banner, outdated-page notice, filter chrome, the grid and the status bar for each pass (MainEditorContentView.swift:602-644).- The status bar sits inside
DataGridModelReader(MainEditorContentView.swift:634-641), which observes the wholeDataGridModel(apple/TablePro/Views/Main/Child/DataGridModelReader.swift:9-15). The model publishesdisplayRevision,selectionRevision,editabilityRevisionandfittingHeight(apple/TablePro/Core/DataGrid/DataGridModel.swift:60-64), so each of those rebuildsStatusBarSnapshotand the column catalog (MainEditorContentView.swift:872-900). ResultStatusBar.bodyis aViewThatFitsover three tier rows (apple/TablePro/Views/Results/ResultStatusBar.swift:32-37). SwiftUI builds and measures each row until one fits, and each row runsReadoutZoneLayout's slot measurement (ResultStatusBar.swift:441-470). That is the 34 ms and 19 ms above.DataTabGridapplies.id(presentation.tabId)(apple/TablePro/Views/Main/Child/DataTabGrid.swift:17-18), so every table tab gets a newDataGridViewControllerfromDataGridRepresentable.makeNSViewController(apple/TablePro/Views/DataGrid/DataGridView.swift:44-46), thoughDataGridViewController.adopt(_:)can move one grid to another model (apple/TablePro/Views/DataGrid/DataGridViewController.swift:118-134).- Above all of it,
MainContentViewis one SwiftUI tree in the split view's content pane (apple/TablePro/Core/Services/Infrastructure/MainSplitViewController.swift:1001-1014), and it observes six objects (apple/TablePro/Views/Main/MainContentView.swift:27-41). Why one tab change re-runs this tree is perf(tabs): one tab change invalidates the views of every tab in the window #4529.
Overlaps #4437: G4b, keep one grid controller across table tabs (tabs.lldb.gridInit.perSwitch is still 1.0). This issue keeps the rest of the table tab around the grid.
Change
Build the table tab the way #3834 built the query tab: AppKit down to its panes, SwiftUI only in leaves that do not depend on the tab list.
- Add a table tab case to
EditorAreaContentnext to.query, backed by aTableTabController(anNSViewController) thatEditorAreaControllercreates once per window and updates in place when the selected tab or its state changes. NoAnyViewroot and norootViewreassignment per pass. - The controller holds one
DataGridViewControllerand callsadopt(_:)with the new tab's model, instead of a new grid per tab (this is perf(grid): wide grid fling and gated items left from #4426 #4437's G4b; land it here or there, once). - The bars above the grid (result-set bar, error banner, outdated-page notice, filter chrome) become views the controller shows or hides. Each one that stays SwiftUI gets its own
NSHostingViewwith a stable root that observes a small model, so a change in one bar does not lay out the others. - The status bar: the controller picks the tier from its own width in
viewDidLayoutand hands it to the bar, so SwiftUI lays out one row, not up to three. The bar reads a per-tab status model that changes only when the counts, timing or selection count change, not on everyDataGridModelpublish. - Size the hosted leaves with
sizingOptionsso AppKit does not ask SwiftUI for intrinsic sizes the layout does not use.
Measure
- Repeat the trace in "Opening a 1M-row PostgreSQL table" (
research/measurements.md): Time Profiler, 10 open-and-close cycles from a sidebar click, Release build, same Mac and fixture. Report main-thread CPU per cycle and the split between SwiftUI graph updates, hosting layout and display. - Target: under 30 ms of main-thread CPU per open-and-close.
apple/scripts/benchmark-app-paths.sh(1,000,000-row table on SQLite, MySQL and PostgreSQL): click to first page drawn, median and p95, against the recorded baseline.- Screenshots of a table tab in light and dark, before and after, at regular, compact and narrow window widths, so the status bar tiers still match.
Part of the performance plan.
Activity