Repository navigation
Backlog
Labels
enhancementNew feature or requestplatform-macosAbout the macOS apprustPull requests that update rust code
Description
Problem
Every Swift driver plugin turns every cell into a Swift String or Data and every row into its own array, even when the engine hands it a native buffer. With #4521, the host would then convert those rows into the core's store, a second pass over every cell. Some plugins pay a third:
- SQL Server and several others read into a cell type of their own, then copy the whole result into
[[PluginCellValue]]. That adds about 24 B per cell and 32 B per row while both copies live, about 250 MB at 1M x 10 on an uncapped read. - DuckDB sends every 2,048-row chunk that has a column outside its plain set (DOUBLE, DATE, TIMESTAMP, DECIMAL and others) through a second SQL execution that casts the chunk to text.
Cause
- The ABI carries rows only as
[[PluginCellValue]]:PluginQueryResult.rows(apple/Plugins/TableProPluginKit/PluginQueryResult.swift:6);- the
@frozenPluginStreamElement.rows([PluginRow]), wherePluginRow = [PluginCellValue](apple/Plugins/TableProPluginKit/PluginStreamTypes.swift:3,:21-25). - Both are fixed: a frozen type's layout cannot change, and the published initializer keeps its exact signature (
PluginQueryResult.swift:49-51).
- SQL Server builds
[[MSSQLRawCell]], then maps every row again intoPluginResult(apple/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift:28-38). The skeleton is copied; theStringandDatapayloads are shared. - DuckDB reads straight from a chunk only when every column is in
typesReadFromChunks(apple/Plugins/DuckDBDriverPlugin/DuckDBTypeRendering.swift:71-76). OtherwisenextBatchprepares a projection and runsresultReader.renderfor each chunk (apple/Plugins/DuckDBDriverPlugin/DuckDBConnection.swift:1154-1181). - PostgreSQL, MySQL and SQLite already hold each value as bytes in libpq's, libmariadb's or SQLite's buffer, and decode it into a
Stringonly to fit the ABI. Examples:LibPQCellDecoding.value(from:oid:)behindapple/Plugins/PostgreSQLDriverPlugin/LibPQPluginConnection+ResultReading.swift:75-88, andSQLiteExecutionBackend.columnValue(apple/Plugins/SQLiteDriverPlugin/SQLiteExecutionBackend.swift:708-720).
Change
Until each engine's data path moves to the core (ADR 0010 slice 5, reordered by #4521), give plugins a second, additive way to deliver rows:
- The sink. A column-batch sink in PluginKit, backed by the core's batch builder from perf(core): decode results straight into typed columns the store keeps #4522. It has typed appends: null, i64, f64, bool, temporal, UTF-8 text from an
UnsafeRawBufferPointer, and bytes. A row end and a batch end return continue or stop, so the row cap, the byte bound and Stop keep working at batch granularity. The bytes go once from the engine's buffer into the column buffer, with noStringper cell. - The ABI. Add it as a new requirement with a default, which the repo's plugin ABI rules count as additive. The default implementation reads the existing
[[PluginCellValue]]path and appends it, so every plugin built before keeps loading. SetTABLEPRO_PLUGINKIT_VERSIONinapple/Configs/PluginKit.xcconfigper that rule, and passapple/scripts/check-pluginkit-abi.sh. - Adoption. PostgreSQL (
PQgetvaluebytes), MySQL, SQLite (sqlite3_column_*) and SQL Server first. DuckDB appends its native vectors and drops the render projection for the types it can read exactly. DuckDB's spellings are checked withapple/scripts/probes/check-column-type-corpus.sh duckdb. - Values unchanged. The text a value shows today stays the same: PostgreSQL's server text, MySQL's charset decode, SQLite's number text.
- A plugin that does not adopt keeps the frozen path unchanged.
Measure
- 1M x 20
trips_1mon PostgreSQL, MySQL and SQLite through the new sink. Instruments Allocations: no_StringStorageor per-row array allocations from the driver. Driver time from the[executeUserQuery] driverTimelog, before and after. - A 1M-row DuckDB table with DOUBLE and TIMESTAMP columns: no
renderexecutions (today about 490 for 1M rows), and wall time before and after. - A 1M-row uncapped SQL Server read: allocation high-water mark before and after.
check-pluginkit-abi.shreports an additive change only.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestplatform-macosAbout the macOS apprustPull requests that update rust code
Activity