Skip to content

perf(export): stream gzip while writing a dump and while reading one back - #4594

Open
datlechin wants to merge 3 commits into
mainfrom
perf/gzip-streaming-dump
Open

datlechin wants to merge 3 commits into
mainfrom
perf/gzip-streaming-dump

Conversation

@datlechin

@datlechin datlechin commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Export:

  • With Compress the file using Gzip on, the dump is deflated as it is written, behind the same atomic temp-file pair. The uncompressed temp .sql and SQLExportCompressor's second pass are gone.
  • Deflate runs on a serial queue of its own fed by a bounded buffer (1 MiB chunks, at most two in flight), so compression overlaps reading the next rows.
  • Split and gzip now work together: each part is a gzip file of its own, dump.part1.sql.gz and so on, finished at rotation, and the split size is the compressed size on disk. A sync flush every min(1 MiB, cap / 32) input bytes keeps the size known to within that, and the writer drains the queue before deciding a part is full. The "split size was not applied" warning goes.
  • A Stop that lands while the last compression drains still publishes nothing: commit(beforePublish:) checks after every part is closed and before any rename.

Import:

  • SQLFileParser reads through SQLFileByteReader: the file itself, or, when it starts with the gzip magic number, the SQL inside it through GzipInflater. Nothing is inflated to disk, and each read inflates about the size asked for, so a block that packs far cannot balloon one read.
  • The dialog's preview is the first 5 MB of inflated text. The up-front statement count is gone (it lexed the whole file once more before Import meant anything). Progress follows the bytes read, compressed bytes for a .sql.gz, and the statements run show as a running count.
  • FileDecompressor and the import's decompressed-copy plumbing (decompressedURL, ownsDecompressedFile, knownStatementCount) are removed.
  • Tests that pinned the removed behavior are replaced: SqlFileImportSourceCleanupTests (the expanded copy it cleaned up no longer exists) by SqlFileImportSourceGzipTests, ImportStatementCountTests (the count is gone), and ImportFileFormatResolverTests drops its FileDecompressor lines.

Measured

512 MB of generated INSERT text, release build, on this Mac under a load average of 87 to 180 from parallel builds, so the times are noisy; the byte counts are exact:

Before After
Export wall time 24.6 s 7.9 s
Export bytes written 607 MB (537 MB temp .sql + 70 MB .gz) 70 MB
Export bytes read back 537 MB 0
Import of the 70 MB .sql.gz, 3.9M statements 150 s (inflate to disk, count, parse) 102 s (parse)
Import temp file 537 MB 0

Test plan

  • SQLExportGzipWriterTests (new): a split gzip dump writes parts of at most 1 MiB that each inflate on their own and join to every statement written; an unsplit one keeps its name; a Stop before publish leaves no file.
  • ExportImportRoundTripTests: the existing gzip case passes, and a new split-and-gzip case restores every row from the parts in order.
  • SQLFileParserGzipTests, SQLFileByteReaderBoundTests (TableProCore): a .sql.gz parses to the statements of the SQL inside it, progress reports compressed bytes against the file's size, a truncated file fails, the preview reads inflated text, and a read of zero-filled gzip stays near the size asked for.
  • GzipDeflaterTests: a sync flush writes out every byte taken so far.
  • SqlFileImportSourceGzipTests, ImportFileFormatResolverTests, SqlFileImportSourceEncodingTests, ImportServiceRunningWorkTests, ImportExecutionGateTests, SQLExportInsertModeTests, SQLExportSessionDeclarationTests; verify.sh plugins.

Docs: TableProApp/docs#297 (draft), the split and gzip sentence and the import dialog step; it merges after this one.

Not in this PR: the iOS app still expands a .gz to a temporary file before its own import, and the SQL Server GO pre-scan is #4555's.

Closes #4553

…back

A gzip export wrote the whole dump uncompressed to a temp file and compressed it in a second pass
after the last row, and could not split. Each part now deflates as it is written, on its own queue,
and a split part is a gzip file of its own. A .sql.gz import inflated the whole file to disk and
lexed it once more to count statements; the parser now reads the gzip file through an inflater and
the count is gone.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:51

This branch has not been deployed

No deployments
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(export): stream gzip while writing a dump and while reading one back

1 participant