Skip to content

perf(results): let a plugin write column bytes straight into the result store #4523

Backlog

Description

@datlechin

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 @frozen PluginStreamElement.rows([PluginRow]), where PluginRow = [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 in toPluginResult (apple/Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift:28-38). The skeleton is copied; the String and Data payloads are shared.
  • DuckDB reads straight from a chunk only when every column is in typesReadFromChunks (apple/Plugins/DuckDBDriverPlugin/DuckDBTypeRendering.swift:71-76). Otherwise nextBatch prepares a projection and runs resultReader.render for 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 String only to fit the ABI. Examples: LibPQCellDecoding.value(from:oid:) behind apple/Plugins/PostgreSQLDriverPlugin/LibPQPluginConnection+ResultReading.swift:75-88, and SQLiteExecutionBackend.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 no String per 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. Set TABLEPRO_PLUGINKIT_VERSION in apple/Configs/PluginKit.xcconfig per that rule, and pass apple/scripts/check-pluginkit-abi.sh.
  • Adoption. PostgreSQL (PQgetvalue bytes), 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 with apple/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_1m on PostgreSQL, MySQL and SQLite through the new sink. Instruments Allocations: no _StringStorage or per-row array allocations from the driver. Driver time from the [executeUserQuery] driverTime log, before and after.
  • A 1M-row DuckDB table with DOUBLE and TIMESTAMP columns: no render executions (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.sh reports an additive change only.

Part of the performance plan; depends on #4521, #4522.

Activity

  1. added
    enhancement
    platform-macos
    rust
    on Nov 25, 2026
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-macosrust

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions