Skip to content

fix(sourcemap): Keep artifact bundles compressed at rest - #2546

Draft
sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/cli-deflate-artifact-bundles
Draft

sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/cli-deflate-artifact-bundles

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Artifact bundles that sentry sourcemap upload sends are stored uncompressed, about 4x larger than needed. The CLI now compresses each ZIP entry with DEFLATE and uploads the chunks with no wire codec.

Since getsentry/cli#849, the CLI builds a STORED ZIP and compresses only the upload chunks with zstd. The Sentry chunk-upload endpoint decodes that zstd before it saves the blobs, so blobs and reassembled bundles go to blob storage without any compression at rest.

This moves the compression work from the upload into the ZIP build. This sends slightly more bytes, because DEFLATE compresses less than zstd. To keep large uploads fast on 2–4 vCPU runners, ZipWriter now compresses entries in parallel at zlib level 4. This PR also fixes an existing bug by no longer holding entry names as small Buffers, which kept shared pool memory and made peak memory grow with the bundle size.

Benchmark

103,662 files (2.0 GiB): real npm package code, minified with esbuild, each with an external sourcemap that includes sourcesContent. Times cover ZIP build, chunk hashing and, for the current CLI, the per-chunk zstd encode.

Current (STORED + zstd per chunk) This PR (DEFLATE per entry)
Stored size 2,071 MiB (101%) 555 MiB (27%)
Bytes uploaded 470 MiB 555 MiB
Chunk requests 259 70
Time, 4 vCPU 24.7s 14.4s
Time, 2 vCPU 27.6s 25.3s
Peak RSS, 4 / 2 vCPU 520 / 531 MiB 392 / 379 MiB

Caveats:

  • Network is not measured. In a real upload the zstd encode runs while chunks are in flight, so the end-to-end gain is likely smaller than the table shows. This PR also sends ~18% more bytes, in fewer requests.
  • Synthetic data on one machine. The files average ~20 KB, smaller than a typical Next.js .next output. All runs used one 4 vCPU Xeon sandbox with a warm page cache. The 2 vCPU rows pin the process to two cores with taskset; they are not a real 2 vCPU runner.
  • Threadpool limit. zlib runs on the libuv threadpool, which has 4 threads by default, so runners with more than 4 cores get no extra speed unless UV_THREADPOOL_SIZE is raised.

via @lcian.

--

View Session [Sentry]

Since the CLI started building STORED ZIPs whenever the server offers a
wire codec, artifact bundles land in storage uncompressed: the server
decodes the per-chunk zstd before saving the blobs, and the assembled
bundle is stored as-is. Large Next.js uploads now store ~4x the bytes.

Always DEFLATE each ZIP entry and send chunks with no wire codec. To
keep this fast on 2-4 vCPU CI runners:

- Compress entries in parallel on the libuv threadpool with an
  in-order writer, so the archive is byte-identical to sequential
  writes. The read-ahead is 16 entries per CPU, capped at 256 MiB.
- Use zlib level 4 instead of 6: ~40% faster for ~4% larger output.
- Write each entry and the central directory with one write call
  instead of 3 and 2 per entry.
- Keep entry names as strings until finalize. Small Buffers are slices
  of Node's shared pool, which zlib also fills, so retaining one per
  entry pinned a 64 KiB slab each, about 1.2x the input in RSS.

Co-Authored-By: Lorenzo <17258265+lcian@users.noreply.github.com>
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 26, 2026 11:05pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 26, 2026 11:05pm UTC

Request Review

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 5535f16c Deployed Nov 26, 2026 by vercel[bot]
Preview – sentry-local — 5535f16c Deployed Nov 26, 2026 by vercel[bot]
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