Skip to content

perf(sidebar): pace the filter by its last refresh and rank Open Quickly without sorting every match - #4433

Merged
datlechin merged 2 commits into
mainfrom
perf/sidebar-openquickly
Nov 23, 2026
Merged

datlechin merged 2 commits into
mainfrom
perf/sidebar-openquickly

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Perf audit 2026-11-22, finding 14 (sidebar and Open Quickly).

  • Open Quickly scores each item without allocating and keeps only the 200 rows it shows (SQ1).
    • FuzzyMatcher.score(_:_:scratch:): an ASCII byte path with two reused rows and no traceback, same scores as match. Anything else (non-ASCII, CR, over 1,024 or 64 characters) takes the Character path.
    • New TopRanked, a bounded heap. The ranking, the browse lists and the Connections scope keep their top rows instead of sorting every match. Ties keep catalog order, as the old sort did.
    • Only the 200 kept rows get their matched character indices.
    • The ranking moved to QuickSwitcherViewModel+Ranking.swift.
  • Open Quickly no longer rereads the database and schema lists after a table open or a query run (SQ5).
    • The catalog store keeps two parts with two keys: the server lists (databases, schemas, routines, triggers, types) and the local ones (saved queries, history). A history write moves only the local key.
  • The sidebar filter waits only as long as the last refresh took, capped at 150 ms, instead of 150 ms after every key but the first (SQ2).
    • New SidebarFilterPacer and RunLoopTurn: a refresh is timed from the filterQuery write to the end of the run loop turn that rebuilt the outline. Each outline reports its rebuild through noteSearchRebuild(for:).
    • A shared state write while a key waits no longer restarts the wait. Typing back to the shown query cancels it.

Measured on an M4 MacBook Pro, interleaved. Before: a Release build of 9d0d481 (universal). After: build.sh app arm64 --unsigned of this branch. Harness: the perf audit's ui-responsiveness (--scenarios catalog, tabs, --quick --no-lldb --no-profile) and db-roundtrips (--engines pg --phases count). Medians, n=6 (catalog) or 4 (tabs); load1 3 to 17, so instruction and statement counts are the numbers to trust.

Metric Before After
Open Quickly, type lc_t250 120 ms apart on 50,000 tables: process instructions 12,721 M 2,107 M
Same: keys that drew a list (of 7) 0 to 1 7
Same: last key to frame 179 ms 66 ms
Sidebar filter tab_ on 26 tables, keys 400 ms apart: later keys minus key 1 147 ms 6 ms
Same: process instructions 1,139 M 1,123 M
Same, keys 100 ms apart: later keys minus key 1 160 ms -2 ms
Sidebar filter t25 on 50,000 tables, 400 ms apart: later keys to frame 199 to 270 ms 58 to 120 ms
Same: process instructions 4,105 M 4,122 M
Same, 100 ms apart, load under 3: worst stall 111 to 112 ms 110 ms
PostgreSQL statements for the second table opened through Open Quickly 10 8
  • The two statements gone are the pg_database and information_schema.schemata reads. The table opened after Database > Refresh still reads both, since a refresh moves the schema generation, as before.
  • Keys 100 ms apart on 50,000 tables cost more CPU (2,930 M to 3,821 M): key 2 now draws its 10,199 rows in some runs instead of folding into key 3. The worst stall is the first key's, the same in both builds.
  • Main-thread ms for the Open Quickly series rose from 44 to 101 ms, because each key now draws its list.

Tests changed on purpose:

  • SidebarViewModelSearchDebounceTests: "filterQuery stays at previous value during debounce window", "filterQuery catches up after debounce window elapses" and "rapid consecutive keystrokes collapse to the final value" pinned a fixed 150 ms; they now run after a slow refresh. "filterQuery clears immediately when search becomes empty" and "filter caches still serve filteredTables using filterQuery, not searchText" report a slow refresh first, since they need a pending wait.
  • QuickSwitcherCatalogStoreTests: "A bumped content revision misses" and "An unscoped content change invalidates every cached connection" split per part. The fixture now keeps one browse scope per case, so a miss test misses only on the field it changes.

Deliberately not fixed here:

  • SQ3 (row content value): the part that stood alone, rows observing AppSettingsManager, already left in feat(settings): native macOS Settings sidebar with pushed pages and history #4413. The rest only pays off with SQ4 or SQ7.
  • SQ4, SQ6, SQ7, SQ8 (row changes for a refined search, the first key on 50,000 tables, a hover tracker, AppKit cells): each is gated on a quiet Time Profiler run, and the quiet pass's ui-responsiveness step aborted. No gate could be decided. The first key t on 50,000 tables still stalls 110 to 170 ms here, at load 3 to 14.
  • The repo's large-catalog baseline (quick-open-result, 184.8 ms) is not re-recorded: it belongs to another machine.
  • Pacing: when the outline rebuilds in a later turn than the write, the clock starts at the rebuild and misses that turn's SwiftUI body work, so on 50,000 tables a key 100 ms after the first can apply early. Results stay correct; the cost is the CPU noted above.

Test plan

  • New: FuzzyMatcherScoreTests (score equals match over ASCII, mixed case, NFC and NFD, emoji, CRLF, 1,025 characters, a 65-character query, every separator), TopRankedTests (equals a stable sort's prefix, ties included), QuickSwitcherRankingTests (the new ranking equals a reference copy of the old one on 5,000 items), SidebarFilterPacerTests, RunLoopTurnTests, six pacing cases in SidebarViewModelSearchDebounceTests, four catalog store cases.
  • Pinned, unchanged: FuzzyMatcherTests, QuickSwitcherViewModelTests, QuickSwitcherCrossSchemaTests, QuickSwitcherRecentIdentityTests, SidebarViewModelTests.
  • verify.sh test on the 12 suites above: 189 passed. Codex adversarial review, then review: clean after the catalog store fixture fix.

@datlechin
datlechin marked this pull request as ready for review November 23, 2026 08:04
@datlechin
datlechin enabled auto-merge (squash) November 23, 2026 08:04
@datlechin
datlechin merged commit 590b022 into main Nov 23, 2026
12 checks passed
@datlechin
datlechin deleted the perf/sidebar-openquickly branch November 27, 2026 16:38
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