Skip to content

Faster directory archives: gzip level 1 default and optional zstd - #52

Merged
sambles merged 3 commits into
mainfrom
feature/fast-archive-compression
Oct 23, 2026
Merged

sambles merged 3 commits into
mainfrom
feature/fast-archive-compression

Conversation

@sambles

@sambles sambles commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Related to OasisLMF/OasisPlatform#1478

Directory archives written by put() used tarfile's default gzip level 9 on a single core. On a 12.36 GB Oasis inputs directory that took 369 s locally (~23 min on a Fargate worker) for a 7.9x ratio. Level 1 takes 32 s for 7.1x.

Faster directory archives

  • Directory archives from put() now default to gzip level 1 instead of 9, about 11x faster on Oasis inputs for ~10% larger archives. The level is configurable with archive_compresslevel.
  • New archive_compression storage option (gz default, or zst) and a per-call put(..., compression=...) override. zstd is multi-threaded (archive_threads, -1 for every core) using the standard library compression.zstd on Python 3.14+, or the zstandard package (new [zstd] extra) on older versions.
  • extract() detects zstd archives from their header, whatever the file name.
  • Removed the unused ARCHIVE_FILE_SUFFIX constant from oasis_data_manager.filestore.backends.base; suffixes come from ARCHIVE_SUFFIXES in oasis_data_manager.filestore.archive.

Changes

  • New oasis_data_manager/filestore/archive.py with compress_dir, open_archive and extract_archive. On Python 3.14+ zstd goes through tarfile's built-in support (tarfile.open(..., "w:zst", options=...) to write, auto-detected on read, so reads can seek). Older versions stream through the zstandard package.
  • BaseStorage takes archive_compression, archive_compresslevel and archive_threads, keeps them in to_config(), and adds archive_suffix().
  • AwsS3Storage.put() passes compression through.
  • Removed the unused ARCHIVE_FILE_SUFFIX constant.

Benchmark (real 12.36 GB inputs, 16-core laptop)

Method Time Archive Ratio
gzip-9 (old default) 369 s 1.564 GB 7.9x
gzip-6 106 s 1.614 GB 7.7x
gzip-1 (new default) 32 s 1.732 GB 7.1x
zstd-3, all cores 16 s 1.417 GB 8.7x

Testing

  • New tests/filestorage/test_archive.py: round trip for gz and zst, the zstandard fallback, the default level, put suffix and per-call override, and to_config() round trip.
  • tests/filestorage/test_local.py passes. Five local-storage "outside root" tests in test_general.py fail the same way without this change.
  • The switch to tarfile's built-in zstd was only checked by hand on Python 3.14 (round trip, extract and member listing for gz and zst); test_archive.py has not been rerun since.

🤖 Generated with Claude Code

Directory archives written by `put()` used tarfile's default gzip level 9 on
a single core. On a 12.4 GB Oasis inputs directory that took 369 s locally
(~23 min on Fargate) for a 7.9x ratio; level 1 takes 32 s for 7.1x.

- Default gzip compresslevel is now 1 (configurable via `archive_compresslevel`)
- New `archive_compression` option ('gz' or 'zst') and per call
  `put(..., compression=...)` override; zstd is multi-threaded
  (`archive_threads`, -1 for every core) via the stdlib `compression.zstd`
  on Python 3.14+ or the `zstandard` package (new `[zstd]` extra)
- `extract()` detects zstd archives by magic bytes
- Archive options are kept by `to_config()`
- New `archive_suffix()` returns the extension for the configured format

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@vinulw vinulw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments but fine to approve as is.

from fsspec.implementations.dirfs import DirFileSystem

from oasis_data_manager.errors import OasisDataManagerException
from oasis_data_manager.filestore.archive import ARCHIVE_SUFFIXES, GZIP, compress_dir, extract_archive, validate_compression

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: ARCHIVE_FILE_SUFFIX variable below not used anywhere, should be removed as ARCHIVE_SUFFIXES takes precendence.

Comment thread oasis_data_manager/filestore/archive.py Outdated
options = {zstd.CompressionParameter.compression_level: level}
if threads and zstd.CompressionParameter.nb_workers.bounds()[1] > 0:
options[zstd.CompressionParameter.nb_workers] = threads
with zstd.ZstdFile(archive_fp, "w", options=options) as zf, tarfile.open(fileobj=zf, mode="w|") as tar:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: tarfile defaults to using compression.zstd if installed. I don't think you need to chain the opening of the tar like this, you can pass the CompressionParameter options via a kwarg options.

sambles and others added 2 commits October 23, 2026 11:22
ARCHIVE_SUFFIXES in filestore/archive.py now determines archive suffixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Write with tarfile.open(..., "w:zst", options=...) and let tarfile
auto-detect zstd on read, instead of wrapping a ZstdFile in a streamed
tar. Reads on 3.14+ are now seekable; the zstandard fallback is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sambles
sambles merged commit 67a9489 into main Oct 23, 2026
3 checks passed
@sambles
sambles deleted the feature/fast-archive-compression branch October 23, 2026 10:42
sambles added a commit that referenced this pull request Oct 23, 2026
Directory archives written by `put()` used tarfile's default gzip level 9 on
a single core. On a 12.4 GB Oasis inputs directory that took 369 s locally
(~23 min on Fargate) for a 7.9x ratio; level 1 takes 32 s for 7.1x.

- Default gzip compresslevel is now 1 (configurable via `archive_compresslevel`)
- New `archive_compression` option ('gz' or 'zst') and per call
  `put(..., compression=...)` override; zstd is multi-threaded
  (`archive_threads`, -1 for every core) via the stdlib `compression.zstd`
  on Python 3.14+ or the `zstandard` package (new `[zstd]` extra)
- `extract()` detects zstd archives by magic bytes
- Archive options are kept by `to_config()`
- New `archive_suffix()` returns the extension for the configured format

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Remove unused ARCHIVE_FILE_SUFFIX constant

ARCHIVE_SUFFIXES in filestore/archive.py now determines archive suffixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Use tarfile's native zstd support on Python 3.14+

Write with tarfile.open(..., "w:zst", options=...) and let tarfile
auto-detect zstd on read, instead of wrapping a ZstdFile in a streamed
tar. Reads on 3.14+ are now seekable; the zstandard fallback is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sambles sambles mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants