fix(core): chunk image processing to reduce memory pressure#315
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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 existingCHUNK_SIZE), aligning with the S3 upload chunking strategy. - Updated
CHUNK_SIZEdocumentation 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; | ||
| }; | ||
|
|
jsfez
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A customer reported the following error on CI:
The PNG itself was valid. The root cause is memory pressure: the optimize & hash step in
upload()ran an unboundedPromise.allover all discovered files, so every screenshot was decoded by sharp/libvips concurrently (the customer's trace showsPromise.all (index 41), i.e. 40+ concurrent decode pipelines). libvips surfaces allocation failures as generic read errors likepngload: libspng read error.Changes
mapInChunkshelper inutil/chunk.tsthat maps over a collection while processing at mostsizeitems concurrently.upload()with the existingCHUNK_SIZE(10), matching the chunking strategy already used for S3 uploads.Test plan
tsc --noEmitpasses🤖 Generated with Claude Code