Skip to content

perf(connections): read the catalog side kinds in one round trip per engine #4543

Done

Description

@datlechin

Problem

After the table list, the sidebar's schemas, routines, triggers, types and server objects each cost one round trip, one after another, and the database list waits behind all of them. In the PostgreSQL statement log (research/pglog/tablepro.log), the first metadata connection sends, in order and one Query each: the table list (07.797), the schema list (07.803), routines (07.807), triggers (07.848), types (07.850), extensions (07.857), then the database list (07.863).

Locally that is 66 ms. Each step is one RTT, so at +50 ms it is an estimated 250-300 ms and at +200 ms about 1.2 s before procedures, types, schema-qualified completion and the database switcher are complete (estimate from the round-trip count, not measured). The table list itself is not delayed. High-latency links make this visible (see closed #1574).

Cause

  • readSideKinds(_:leasingFrom:scope:) loops over SideKind.allCases and takes one withMetadataDriver lease per kind, awaiting each before the next (apple/TablePro/Core/Services/Query/SchemaService+CatalogLoad.swift:136-159). The comment at :13-14 gives the reason: a column read asked for meanwhile goes before the next kind.
  • A refresh runs the same kinds with async let on one driver (SchemaService+CatalogLoad.swift:115-134), but one connection serves them one Query at a time, so it is still one RTT per kind. A DDL statement from the editor triggers that full refresh (apple/TablePro/Core/Services/Query/SchemaRefreshService.swift:279-325).
  • loadSchema awaits the whole load, then syncAutocompleteNamespaces, then loadDatabases (apple/TablePro/Views/Main/Extensions/MainContentCoordinator+SchemaLoading.swift:118-147). fetchDatabaseList resolves to the browse scope and lands on the same pooled interactive entry (apple/TablePro/Core/Services/Query/DatabaseTreeMetadataService.swift:596-608), so started earlier it would still queue on that entry between kinds.
  • PostgreSQL already has a one-Query multi-read path, executeCatalogReads with LibPQCatalogBatch (apple/Plugins/PostgreSQLDriverPlugin/LibPQDriverCore.swift:349, apple/Plugins/PostgreSQLDriverPlugin/LibPQCatalogBatch.swift:11). The catalog load does not use it.
  • MySQL connects with CLIENT_FOUND_ROWS only, no multi-statements (apple/Plugins/MySQLDriverPlugin/MariaDBPluginConnection+Transport.swift:44), but it already pipelines two mysql_send_query calls and reads the replies in order (sendWithSelectLimit, apple/Plugins/MySQLDriverPlugin/MariaDBPluginConnection.swift:959-1000).

Overlaps #4459: C5c already covers sending queued PostgreSQL catalog reads as one Query (a read queue in LibPQDriverCore). This issue adds the host side (one lease for all kinds), the other engines and the database list.

Change

  • Add a driver capability that reads several catalog kinds in one round trip and returns one result per kind, with a default that runs them one by one. PostgreSQL implements it with executeCatalogReads (one Query, one SET LOCAL search_path); MySQL pipelines the reads with mysql_send_query and reads the replies in order. Other engines keep the default until each is measured.
  • readSideKinds takes one lease for all side kinds and commits each kind as its result arrives, as today. Keep the column-read priority by checking the entry's waiter queue between result sets instead of taking a fresh lease per kind.
  • Put the database list in the same round trip where the engine allows, or start it alongside the load, knowing it shares the entry.
  • The refresh path uses the same capability.

Measure

  • Statement log and packet capture: one round trip for the side kinds after the table list, on PostgreSQL and MySQL.
  • Signposts from tables visible to the last side kind committed and to the database switcher filled, at +50 ms and +200 ms RTT, median of 10. Target: (kinds - 1) x RTT less than today.

Part of the performance plan.

Activity

  1. added
    enhancement
    platform-macos
    on Nov 25, 2026
  2. datlechin commented on Nov 25, 2026

    @datlechin
    MemberAuthor

    #4576 ships the host side (one lease and one driver call for every side kind, the refresh path included), the PluginKit capability with a one-by-one default, the PostgreSQL one-Query read, and the database list read beside the load. Left for a follow-up:

    • MySQL: pipelining the routine and trigger reads with mysql_send_query goes through the execute path's reconnect, select-limit and footprint handling, which is its own driver change. MySQL keeps the one-by-one default, on the one lease, for now.
    • The database list in the same PostgreSQL Query: it is read by DatabaseTreeMetadataService with its own state, dedup and fence, so it now starts beside the load instead of riding the batch.
    • The column-read priority between kinds is gone by design: a column read waits for the one side read instead of slipping between kinds.
    • Statement log and signpost timings at +50 ms and +200 ms were not run here.
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

    enhancementplatform-macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions