Skip to content

perf(export): buffer CSV and JSON output and cap Parquet staging memory - #4333

Merged
datlechin merged 5 commits into
mainfrom
perf/export-output
Nov 18, 2026
Merged

datlechin merged 5 commits into
mainfrom
perf/export-output

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • P21: CSV and JSON exports write through PluginExportOutputBuffer in apple/Plugins/Shared, which holds 1 MiB between writes.
  • P21: CSV builds its write options once per export. A value goes out as is only when a byte scan proves no rule applies; every other value takes the existing escaping path.
  • P21: JSON reads each column's type once, skips escapeJSONString for text with nothing to escape, and passes canonical numbers through.
  • P21: PluginHexText replaces per-byte String(format:) in the CSV, XLSX, Markdown and Parquet exports and the SQL export's own copy. PluginCellValue.sortKey uses the same table, with no ABI change.
  • P23: Parquet staging sets memory_limit to a sixteenth of RAM, from 1 to 4 GiB.
  • P23: the limit lifts in place for a value larger than it, for rows too wide to spill, and once spilling reaches a quarter of the free disk, so an export that works on main still works.
200,000 rows, 10 columns main this PR
CSV, default options 1.20 s 0.08 s
JSON, default options 1.52 s 0.17 s
32 byte cell main this PR
sortKey 16,025 ns 205 ns
Parquet, 40,000,000 rows main this PR
Peak memory 5.69 GB 2.35 GB
CPU (user) 76.4 s 90.7 s
Elapsed 59.6 s 62.5 s

Test plan

  • New in FormatPluginTests: PluginExportOutputBufferTests, PluginHexTextTests, ParquetStagingMemoryTests, ExportOutputStabilityTests.
  • apple/scripts/probes/check-parquet-export-values.sh now stages a 1.2 GiB value, 50,000 rows of 64 KiB and a spent spill budget against the shipped DuckDB. It fails with either recovery path disabled.
  • 124,704 CSV and JSON exports across every option, encoding and a hostile value corpus: SHA-256 identical to main.
  • Parquet at 12,000,000 and 40,000,000 rows: row count and content checksum identical to main.
  • 40,000,000 rows with spill files on a 300 MB volume: completes with the same checksum. With the spill budget removed it fails at 18,656,000 rows.
  • verify.sh build, plugins, abi and lint pass. SQLiteDriverTests, FormatPluginTests, TableRowsSortingTests and PluginCellValueSortKeyTests pass.
  • The iOS app builds for the simulator. TableProMobileTests did not run locally, since this machine has no simulator runtime.

@datlechin
datlechin enabled auto-merge (squash) November 18, 2026 21:19
@datlechin
datlechin merged commit 76e7246 into main Nov 18, 2026
14 checks passed
@datlechin
datlechin deleted the perf/export-output branch November 19, 2026 02:00
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.

1 participant