You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce heap usage in Zip archiver to prevent OutOfMemoryError in CI builds (#390)
* Reduce heap usage threshold from 100MB to 10MB in ConcurrentJarCreator
The previous threshold of 100000000 (100MB) divided by number of threads was causing
OutOfMemoryError issues when creating zip archives, particularly in environments with
limited heap space like CI systems. The ByteArrayOutputStream used internally can grow
up to 2x the threshold before switching to disk-based storage, leading to excessive
memory consumption.
Reducing to 10000000 (10MB) reduces memory pressure while still maintaining reasonable
performance. For typical builds with 4 threads, this means:
- Before: 25MB per stream (potentially 50MB+ with buffer doubling)
- After: 2.5MB per stream (potentially 5MB+ with buffer doubling)
This change addresses the heap space errors reported in apache/maven CI builds.
Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
* Add maximum buffer size cap to ByteArrayOutputStream
Cap individual buffer allocations to 16MB to prevent excessive memory usage.
The previous implementation allowed buffers to double indefinitely, which could
lead to very large single allocations (32MB, 64MB, 128MB, etc.) that contribute
to heap exhaustion.
With this cap, when more than 16MB of data needs to be stored, the
ByteArrayOutputStream will create multiple 16MB buffers instead of one giant
buffer. This spreads the memory allocation across multiple smaller chunks
and prevents heap fragmentation issues.
Combined with the reduced threshold in ConcurrentJarCreator, this provides
defense-in-depth against OutOfMemoryError during zip archive creation.
Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
0 commit comments