Skip to content

perf(results): run the adapter's side of every driver call off the main actor - #4595

Merged
datlechin merged 4 commits into
mainfrom
perf/driver-calls-off-main
Nov 27, 2026
Merged

datlechin merged 4 commits into
mainfrom
perf/driver-calls-off-main

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • PluginDriverAdapter's async entry points are @concurrent, so the adapter's own work around a driver call leaves the main actor: the statement checks in admit (the NUL scan and the database-move classifier, both linear in the text), the statement's lexical description, readSchema, and the mapping of the answer (mapQueryResult, fetchAllColumns and fetchAllForeignKeys over a whole schema, routines and types sorted).
  • The [Any?] entry points (executeUserQuery, executeParameterized, executeBatch) convert their parameters on the caller's actor, since [Any?] is not Sendable, and hand the Sendable values to a private @concurrent body that does the rest.
  • QueryExecutor.fetchBoundedQueryData, fetchExplainPlan and fetchQueryData are @concurrent, and the comment that called them background work without it is gone. fetchQueryDataParameterized stays on its caller: its [Any?] cannot cross, and its driver call leaves at the adapter.
  • The lease, admission and result install stay on the main actor. PluginKit does not change.

What the measurement showed: the driver call itself already ran off the main thread. TableProPluginKit is the one target built without SWIFT_APPROACHABLE_CONCURRENCY, so each PluginDatabaseDriver requirement keeps the old nonisolated async meaning and hops to the global executor; the plugin's own work after an await (MongoDB's flatten, ClickHouse's classify, PluginBoundedStream.collect) runs there. What stayed on main was the adapter's side of each call.

Test plan

  • PluginDriverAdapterIsolationTests (new): a stub driver records whether the adapter read its state, and whether its own calls ran, on the main thread, for a user query, a parameterized one, a bounded read through PluginBoundedStream.collect, QueryExecutor.fetchQueryData and a catalog read, each called from a @MainActor test. On main the adapter's reads happen on the main thread and every case fails; here all five pass. The driver's own calls are off the main thread on both.
  • verify.sh test PluginDriverAdapterIsolationTests PluginDriverAdapterConcurrencyTests PluginDriverAdapterParameterTests PluginDriverAdapterStatementContextTests PluginRowLocatorTests ApprovedTargetTests.
  • Not run here: the Time Profiler and Hangs passes against live MongoDB and ClickHouse servers.

Closes #4530

…in actor

Under NonisolatedNonsendingByDefault the adapter's async entry points ran on their
caller's actor, the main one, so the statement checks, the statement's description
and the mapping of each answer ran there. They are @Concurrent now, and the [Any?]
entry points convert their parameters first. QueryExecutor's fetches are @Concurrent
too. The driver call itself already left: PluginKit builds without the feature.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:51
…DriverAdapter

Maintenance, object comments, materialized views, table options, sequences
and view templates move to PluginDriverAdapter+ObjectEditing.swift, and the
transaction calls to PluginDriverAdapter+Transactions.swift. Behavior and
access are unchanged. This brings the class body and the file back under
the SwiftLint type_body_length and file_length limits.
@datlechin
datlechin disabled auto-merge November 27, 2026 04:09
@datlechin
datlechin merged commit d465598 into main Nov 27, 2026
19 of 20 checks passed
@datlechin
datlechin deleted the perf/driver-calls-off-main branch November 27, 2026 04:09
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.

perf(results): driver calls and the work after each await run on the main actor

1 participant