Description
Problem
Typing in the sidebar filter on a large catalog stalls the window. On 50,000 tables the first key t still stalls 110 to 170 ms on an M4 MacBook Pro (#4433, #4438), and the work is linear in the catalog, so 100,000 tables should cost about twice that (not yet measured). The pacer from #4433 spaces the refreshes out but does not make them cheaper. Nobody has profiled how that time splits between the name scan and the outline reload.
Cause
- The scan.
SidebarNameQuery.tier(of:)bridges each name toNSStringand callslocalizedStandardRange(of:), a locale-aware case- and diacritic-insensitive search, for every candidate (apple/Packages/TableProMacCore/Sources/TableProUtilities/UI/SidebarNameFilter.swift:24-31).SidebarSearch.rankedruns it over every item (apple/Packages/TableProMacCore/Sources/TableProUtilities/UI/SidebarSearch.swift:56-69), andDatabaseTreeFilter.filteredTablesthen dedups the matches through aSetofTableIdentity(apple/TablePro/Views/Sidebar/DatabaseTreeFilter.swift:208-226). - On the main actor, from scratch.
SidebarViewModelis@MainActor(apple/TablePro/ViewModels/SidebarViewModel.swift:12). Its memo is keyed on the rows and the query (SidebarViewModel.swift:465-469,:499-509), and the outline's bucket cache is keyed on the search text (apple/TablePro/Views/Sidebar/DatabaseTreeOutlineCoordinator+Nodes.swift:703-715), so every new query rescans the whole catalog, even whenordcan only narrow the matches ofor.SidebarFilterPaceronly decides how long a key waits (apple/TablePro/ViewModels/SidebarFilterPacer.swift:13-29). - The nodes. For each matched row outside the kept head and tail,
tableNodesbuilds a new id string withDatabaseTreeNode.tableId(ref)and looks it up innodeCache(DatabaseTreeOutlineCoordinator+Nodes.swift:890-932,apple/TablePro/Views/Sidebar/DatabaseTreeNode.swift:222-224), andrebuildclearschildrenCache(apple/TablePro/Views/Sidebar/DatabaseTreeOutlineCoordinator.swift:303-314). Narrowing applies as row removals; the first key, a widening and a clear fall back to a reload (apple/TablePro/Views/Sidebar/DatabaseTreeOutlineCoordinator+RowChanges.swift:31-39). - The bodies redo the filter.
SidebarTreeView.visibleSchemas, evaluated inbody, callsDatabaseTreeFilter.hierarchicalLoadedContentwith its defaultfilter: { $0.filtered() }for every loaded schema, with no memo (apple/TablePro/Views/Sidebar/SidebarTreeView.swift:48-70,DatabaseTreeFilter.swift:343-350). In the flat shape,SidebarView.otherSchemaMatchesandattachedSchemaMatchescallDatabaseTreeFilter.loadedObjectBuckets, also unmemoized (apple/TablePro/Views/Sidebar/SidebarView.swift:43-100,DatabaseTreeFilter.swift:590). The outline coordinator already holds the same verdicts inbucketMemoandloadedContentMemo(DatabaseTreeOutlineCoordinator.swift:45-46). Any unrelated publish to these views during a search repeats the full filter. SidebarView.initcallsSidebarViewModel.shared, which callsupdateBindingsand assigns three@Publishedbindings (SidebarView.swift:141-148,SidebarViewModel.swift:48-56,:200-202). Each assignment sendsobjectWillChangeand re-runs the sidebar bodies above, though the comment atSidebarView.swift:148says nothing observable is written there.
Overlaps #4438: SQ4 (apply a refined search as row changes), SQ6 (cut the row build of a search on a large catalog, the 110-170 ms first key), SQ7 (hover tracking during scroll) and SQ8 (AppKit object tree cells). This issue keeps the scan, the off-main filter, the interned nodes and the duplicate body filters. The node interning below is the row-build part of SQ6; land it once.
Change
- Fold once. When a catalog buffer lands, build a search index for it off the main actor: each name folded with
folding(options: [.caseInsensitive, .diacriticInsensitive, .widthInsensitive], locale:)and kept as contiguous UTF-8, keyed by the sameSameRowsidentity the memos use. Fold the query once per key and match bytes; the tier is the match position (exact, prefix or substring).localizedStandardRangealso applies locale equivalences that folding does not, so first pin today's results inSidebarNameFilterTestsandSidebarSearchTests(apple/Packages/TableProMacCore/Tests/TableProUtilitiesTests/) with non-ASCII cases (ß, ligatures, Turkish i), then switch. - Off main, with cancellation. Run the scan in a
@concurrentfunction over theSendableindex, asQuickSwitcherViewModel.buildTableItemsalready does (apple/TablePro/ViewModels/QuickSwitcherViewModel.swift:1107-1108). Cancel a superseded pass, apply the result on main only if its query is still current, and when the new query extends the previous one, filter only the previous match indices. - One node per table. Build the outline nodes once per catalog load, parallel to the catalog buffer, so a filter result maps match indices to existing nodes with no string building. Write a node's
kindonly when its drawn fields changed. - One owner for the verdicts. Move the bucket memo to
SidebarViewModel(or expose the coordinator's), pass it asfilter:tohierarchicalLoadedContentandloadedObjectBuckets, and haveSidebarTreeViewandSidebarViewread the memoized verdicts. Computeschemasonce per body. - Keep the three bindings in
SidebarViewModelas plain properties: they are plumbing, not drawn state.
Measure
apple/scripts/benchmark-large-catalog.shsidebar-filterstep, with a 100,000-table MySQL fixture fromapple/scripts/probes/build-large-catalog-fixtures.sh(TABLES=100000) next to the 50,000 one: median and p95 per key, and the script's main-thread stall check.- Target: no main-thread stall over 100 ms on any key at 100,000 tables, the budget the script already applies (Measure the sidebar, Open Quickly and autocomplete on 100 schemas and 50,000 tables #3661), and no scan samples on the main thread.
- Time Profiler over a scripted
o,or,ord, then clear, on 100,000 tables in the flat layout and on 100 schemas of 500 tables in the hierarchical one: main-thread ms split between the scan,tableNodes,rebuildand NSOutlineView. Measure the NSOutlineView part before deciding anything about the flat shape's view. - A Debug counter of
DatabaseTreeObjectBucketsbuilt per key on a 50-schema hierarchical connection. Target: one per schema per query, not two or more.
Part of the performance plan.
Activity
datlechin commentedon Nov 26, 2026
#4596 ships the part that stands alone: the ASCII byte search (about 20 ms to 2 ms per key over 100,000 names), one memo of container verdicts for the bodies around the outline, and the bindings as plain properties. Left: the scan in a
@concurrentpass with cancellation and narrowing from the previous matches, and the outline nodes built once per catalog load (SQ6 of #4438). The filter's callers, the outline's node build and the SwiftUI bodies, read its verdicts synchronously, so moving the scan off the main actor turns them into an async pipeline, which is its own change. The 100,000-tablebenchmark-large-catalog.shrun and the Time Profiler split were not taken: the shared Mac ran out of disk during this run.