ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r677272 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/zip/ZipOutputStream.java
Date Wed, 16 Jul 2008 12:58:11 GMT
Author: bodewig
Date: Wed Jul 16 05:58:10 2008
New Revision: 677272

URL: http://svn.apache.org/viewvc?rev=677272&view=rev
Log:
feed Deflater smaller chunks because it seems to copy around the data a lot.  PR 45396.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=677272&r1=677271&r2=677272&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jul 16 05:58:10 2008
@@ -179,6 +179,10 @@
    an SSH session providing (local and remote) tunnels.
    Bugzilla Issue 43083.
 
+ * ZipOutputStream has been sped up for certain usage scenarios that
+   are not used by Ant's family of zip tasks.
+   Bugzilla report 45396.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java?rev=677272&r1=677271&r2=677272&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java Wed Jul 16 05:58:10
2008
@@ -58,6 +58,14 @@
     private static final int SHORT = 2;
     private static final int WORD = 4;
     private static final int BUFFER_SIZE = 512;
+    /* 
+     * Apparently Deflater.setInput gets slowed down a lot on Sun JVMs
+     * when it gets handed a really big buffer.  See
+     * https://issues.apache.org/bugzilla/show_bug.cgi?id=45396
+     *
+     * Using a buffer size of 8 kB proved to be a good compromise
+     */
+    private static final int DEFLATER_BLOCK_SIZE = 8192;
 
     /**
      * Compression method for deflated entries.
@@ -482,9 +490,21 @@
         if (entry.getMethod() == DEFLATED) {
             if (length > 0) {
                 if (!def.finished()) {
-                    def.setInput(b, offset, length);
-                    while (!def.needsInput()) {
-                        deflate();
+                    if (length <= DEFLATER_BLOCK_SIZE) {
+                        def.setInput(b, offset, length);
+                        deflateUntilInputIsNeeded();
+                    } else {
+                        final int fullblocks = length / DEFLATER_BLOCK_SIZE;
+                        for (int i = 0; i < fullblocks; i++) {
+                            def.setInput(b, offset + i * DEFLATER_BLOCK_SIZE,
+                                         DEFLATER_BLOCK_SIZE);
+                            deflateUntilInputIsNeeded();
+                        }
+                        final int done = fullblocks * DEFLATER_BLOCK_SIZE;
+                        if (done < length) {
+                            def.setInput(b, offset + done, length - done);
+                            deflateUntilInputIsNeeded();
+                        }
                     }
                 }
             }
@@ -915,4 +935,10 @@
         }
     }
 
+    private void deflateUntilInputIsNeeded() throws IOException {
+        while (!def.needsInput()) {
+            deflate();
+        }
+    }
+
 }



Mime
View raw message