Reduce heap usage in Zip archiver to prevent OutOfMemoryError in CI builds #390
+10
−1
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.
Problem
The Zip archiver was causing
OutOfMemoryError
in CI builds with limited heap space, particularly affecting projects like apache/maven. The error occurred during archive creation:Root Cause
The
ConcurrentJarCreator
was using an aggressive 100MB memory threshold divided by thread count for managing in-memory buffers. TheByteArrayOutputStream
implementation would double its buffer size as needed (1MB → 2MB → 4MB → 8MB → 16MB → 32MB → ...), which could lead to very large single allocations before the threshold would trigger switching to disk-based storage.For a typical 4-thread build:
Solution
This PR implements two complementary changes to reduce memory pressure:
1. Reduced Memory Threshold (10x reduction)
Changed the threshold in
ConcurrentJarCreator
from 100MB to 10MB:2. Buffer Size Cap
Added a 16MB maximum buffer size in
ByteArrayOutputStream
to prevent unbounded growth:When more than 16MB of data needs to be stored, multiple 16MB buffers are created instead of one giant buffer, preventing heap fragmentation and excessive single allocations.
Impact
Memory Usage (4 threads):
Performance:
Testing
Fixes heap space errors reported in https://github.com/apache/maven/actions/runs/18203002937/job/51826915272 and related CI builds.
Original prompt
This section details on the original issue you should resolve
<issue_title>Heap usage by Zip archiver</issue_title>
<issue_description>We need an investigate heap usage be Zip archiver, in
ConcurrentJarCreator
there is a buffer about 100MB used ...plexus-archiver/src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java
Line 117 in 7ed88ad
reference:
Comments on the Issue (you are @copilot in this section)
@slachiewicz also visible in apache/maven project (main branch) CI