Skip to content

Commit 218c78a

Browse files
Use BufferedOutputStream when writing the Zip file to improve performance (#1579)
* fix: use buffered writes for performance When not using STORED entries use a BufferedOutputStream to avoid lots of small writes to the file system. Testing this with a 300mb jar build I see the total build time going from 40s to 30s. Note that it is not possible to do this with STORED entries as the implementation requires a RandomAccessFile to update the CRC after write. * Cleanup --------- Co-authored-by: Goooler <[email protected]>
1 parent 73933ea commit 218c78a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/docs/changes/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
## [Unreleased]
55

6+
**Changed**
7+
8+
- Use `BufferedOutputStream` when writing the Zip file to improve performance. ([#1579](https://github.com/GradleUp/shadow/pull/1579))
69

710
## [v8.3.8] (2025-07-01)
811

src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class DefaultZipCompressor implements ZipCompressor {
3030
@Override
3131
ZipOutputStream createArchiveOutputStream(File destination) {
3232
try {
33-
ZipOutputStream zipOutputStream = new ZipOutputStream(destination)
33+
ZipOutputStream zipOutputStream = entryCompressionMethod == ZipOutputStream.STORED ?
34+
new ZipOutputStream(destination) :
35+
// It is not possible to do this with STORED entries as the implementation requires a RandomAccessFile to update the CRC after write.
36+
new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destination)))
3437
zipOutputStream.setUseZip64(zip64Mode)
3538
zipOutputStream.setMethod(entryCompressionMethod)
3639
return zipOutputStream

0 commit comments

Comments
 (0)