Skip to content

perf(memory): build each result row at its exact size in every driver - #4563

Merged
datlechin merged 5 commits into
mainfrom
perf/exact-row-capacity
Nov 27, 2026
Merged

datlechin merged 5 commits into
mainfrom
perf/exact-row-capacity

Conversation

@datlechin

@datlechin datlechin commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • On the macOS 13 and iOS 18 deployment targets, EnumeratedSequence is only a Sequence (its Collection conformance needs the OS 26 standard library), so x.enumerated().map cannot reserve its count and grows each row by doubling.
  • Every per-row builder now maps over indices, which allocates exactly count: PostgreSQL single-row reads (table pages, Fetch All, bounded reads), MongoDB flattening, ClickHouse TabSeparated rows and the binary-column demote pass, Snowflake and BigQuery rows, the core QueryResultStreaming rows, and the two iOS plugin row emitters (PluginBackedDriver, PluginGridValue).
  • The row-of-enums shape itself stays for perf(results): hold every Mac result in the core's columnar store #4521.

Measured

  • Probe built with -target arm64-apple-macosx13.0: a 20-cell row from enumerated().map has capacity 36 and malloc_size 896 B; from indices.map, capacity 20 and 512 B. Built for macOS 26, both give 20 and 512 B, which is why a scratch test on a current target sees no waste.
  • That is 384 B per 20-column row: about 384 MB per million rows, the gap the issue measured between PostgreSQL (896 MB of row arrays) and MySQL (512 MB) on trips_1m. The phys_footprint run with the app was not repeated here.

Test plan

  • New tests decode a 20-column row through each engine's real row builder and check capacity == count: LibPQSingleRowCapacityTests (a client-built PGresult), ClickHouseTabSeparatedRowDecoderTests, ClickHouseResponseClassifierTests (demote path), QueryResultStreamingTests, and MongoDBPluginConnectionTests on iOS.
  • On the old code the three package tests fail (swift test --filter ExactCapacity: 3 executed, 3 failed); with the change they pass (3 of 3). The iOS test runs on CI only, since this Mac has no simulator runtime.
  • verify.sh build and verify.sh plugins pass; Snowflake, BigQuery and MongoDB are registry plugins with no macOS test target.
  • Main merged in twice. The ClickHouse decoder took main's version from perf(drivers): decode ClickHouse and SQL Server cells without per-field copies #4581, which reserves the row at its column count, and both sides' tests were kept, the exact-capacity case included.
  • After the merge: verify.sh --jobs 4 build PASS, plugins PASS, test over LibPQSingleRowCapacityTests, LibPQSingleRowReadTests, ClickHouseTabSeparatedRowDecoderTests, ClickHouseResponseClassifierTests and QueryResultStreamingTests PASS: 7 executed in the Unit plan and 60 under swift test, none failed.
  • iOS: build-for-testing of TableProMobile for the generic simulator succeeds, so MongoDBPluginConnectionTests compiles. This Mac has no simulator runtime, so the iOS suite itself runs on CI only. The earlier red iOS and Package Tests never ran: it was cancelled after 24 hours in the queue.
  • Codex review and security pass on the merge: clean.

Closes #4520

On the macOS 13 and iOS 18 deployment targets an enumerated sequence is not a
Collection, so `enumerated().map` cannot reserve its count and grows the row by
doubling: a 20-cell row ends at capacity 36, 896 bytes instead of 512. Map over
`indices` in every per-row builder: PostgreSQL single-row reads, MongoDB
flattening, ClickHouse TabSeparated rows and the binary demote pass, Snowflake,
BigQuery, the core result stream and the iOS plugin row emitters.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:50
# Conflicts:
#	apple/Packages/TableProCore/Tests/TableProPluginKitTests/ClickHouseTabSeparatedRowDecoderTests.swift
#	apple/Plugins/TableProPluginKit/ClickHouseTabSeparatedRowDecoder.swift
@datlechin
datlechin merged commit 873fc11 into main Nov 27, 2026
2 of 3 checks passed
@datlechin
datlechin deleted the perf/exact-row-capacity branch November 27, 2026 16:36
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(memory): build each result row at its exact size in every driver

1 participant