Reduce peak memory in getFileHashes #1258
Open
hamidrezahanafi wants to merge 1 commit intochromaui:mainfrom
Open
Reduce peak memory in getFileHashes #1258hamidrezahanafi wants to merge 1 commit intochromaui:mainfrom
getFileHashes #1258hamidrezahanafi wants to merge 1 commit intochromaui:mainfrom
Conversation
… of one buffer per file
getFileHashes by pooling read buffers instead of one buffer per filegetFileHashes
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1258 +/- ##
==========================================
+ Coverage 72.22% 72.46% +0.23%
==========================================
Files 208 208
Lines 7918 7961 +43
Branches 1435 1450 +15
==========================================
+ Hits 5719 5769 +50
+ Misses 2177 2170 -7
Partials 22 22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Reduce peak memory in
getFileHashesby pooling read buffers instead of one buffer per file.Storybook builds with many static assets caused Chromatic CLI to pre-allocate a 64KiB buffer per file before hashing, so memory scaled as O(files × 64KiB) and could push CI containers over their limit. This change reuses a small buffer pool sized to min(concurrency, file count), so allocation is O(concurrency × 64KiB) while preserving the same hashing behavior.
Changes
Buffer.allocUnsafe(64 * 1024)upfront with acquire/release from a fixed pool tied top-limitconcurrency.CHROMATIC_HASH_CONCURRENCYto a safe range and handlefiles.length === 0without doing work.allocUnsafecalls; equality of hashes forconcurrency: 1vs higher concurrency, including one file > 64KiB to exercise incremental reads under pooling.Benchmark (local, 3000 small files, concurrency 8,
NODE_OPTIONS=--expose-gc)Measured with
process.memoryUsage()before/after a full hash pass; legacy implementation duplicated the pre-pool “one buffer per file” strategy for comparison.arrayBuffersexternalheapUsedMost of the legacy cost shows up under
arrayBuffers/external(Buffer backing memory), not V8heapUsed. Pooled behavior aligns with 3000 × 64 KiB ≈ 187.5 MiB no longer being held for read buffers at once.Notes