Skip to content

fix(core): chunk image processing to reduce memory pressure#315

Merged
gregberge merged 1 commit into
mainfrom
fix/chunk-image-processing
Jun 10, 2026
Merged

fix(core): chunk image processing to reduce memory pressure#315
gregberge merged 1 commit into
mainfrom
fix/chunk-image-processing

Conversation

@gregberge

Copy link
Copy Markdown
Member

Summary

A customer reported the following error on CI:

Error: Error while processing image (...): pngload: libspng read error
    at optimizeScreenshot (.../@argos-ci+core@6.1.0/.../index.mjs:1316:9)
    at async Promise.all (index 2)

The PNG itself was valid. The root cause is memory pressure: the optimize & hash step in upload() ran an unbounded Promise.all over all discovered files, so every screenshot was decoded by sharp/libvips concurrently (the customer's trace shows Promise.all (index 41), i.e. 40+ concurrent decode pipelines). libvips surfaces allocation failures as generic read errors like pngload: libspng read error.

Changes

  • Add a mapInChunks helper in util/chunk.ts that maps over a collection while processing at most size items concurrently.
  • Use it in the optimize & hash step of upload() with the existing CHUNK_SIZE (10), matching the chunking strategy already used for S3 uploads.

Test plan

  • tsc --noEmit passes
  • All 78 core package tests pass

🤖 Generated with Claude Code

Screenshots were optimized and hashed with an unbounded Promise.all,
so every image was decoded by sharp/libvips concurrently. With large
suites this caused memory pressure and libvips failures such as
"pngload: libspng read error". Process files in chunks of 10, like
the S3 upload step already does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 10, 2026 14:21
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
argos-js-sdk-reference Ready Ready Preview, Comment Jun 10, 2026 2:22pm

Request Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces memory pressure during upload() by limiting concurrency in the “optimize screenshot + compute hashes” phase, avoiding an unbounded Promise.all that can decode many images concurrently via sharp/libvips.

Changes:

  • Added mapInChunks() utility to process an array with bounded concurrency.
  • Updated upload() to use chunked processing for optimize/hash (using existing CHUNK_SIZE), aligning with the S3 upload chunking strategy.
  • Updated CHUNK_SIZE documentation to reflect its broader role (processing + uploading).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/util/chunk.ts Adds mapInChunks() helper for bounded async mapping.
packages/core/src/upload.ts Uses mapInChunks() to limit concurrent image optimize/hash work.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 14 to +17

return result;
};

@gregberge gregberge merged commit 6e0f17c into main Jun 10, 2026
89 of 91 checks passed
@gregberge gregberge deleted the fix/chunk-image-processing branch June 10, 2026 14:53
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.

3 participants