JDK-6448468 : ZipOutputStream very very slow in 1.5.0_07
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-07-13
  • Updated: 2011-02-16
  • Resolved: 2006-07-13
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP, Windows 2000

A DESCRIPTION OF THE PROBLEM :
A simple one entry ZipOutputStream is dramatically slower in 1.5.0_07 to the point of being unusable for even modest sized arrays.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the attached code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Here are previous JVM / OS combinations(size is bytes, time is seconds):

1.3.1_01 Win XP
size: 1000 time: 0.078
size: 10000 time: 0.0
size: 100000 time: 0.016
size: 1000000 time: 0.282
size: 10000000 time: 1.016
size: 20971520 time: 2.094

1.4.2_07 WIN 2000
size: 1000 time: 0.02
size: 10000 time: 0.0
size: 100000 time: 0.01
size: 1000000 time: 0.22
size: 10000000 time: 1.492
size: 20971520 time: 3.095

1.4.2_12 WIN XP
size: 1000 time: 0.109
size: 10000 time: 0.0
size: 100000 time: 0.016
size: 1000000 time: 0.203
size: 10000000 time: 1.782
size: 20971520 time: 4.125

1.5.0_02 WIN XP
size: 1000 time: 0.078
size: 10000 time: 0.0
size: 100000 time: 0.031
size: 1000000 time: 0.234
size: 10000000 time: 1.718
size: 20971520 time: 3.484

1.5.0_06 WIN 2000
size: 1000 time: 0.01
size: 10000 time: 0.01
size: 100000 time: 0.02
size: 1000000 time: 0.241
size: 10000000 time: 1.522
size: 20971520 time: 3.375



ACTUAL -
Here are the timings for _07

1.5.0_07 Win XP
size: 1000 time: 0.0
size: 10000 time: 0.016
size: 100000 time: 0.031
size: 1000000 time: 1.813
size: 10000000 time: 251.661
size: 20971520 time: 1148.644

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.io.*;
import java.util.Random;
import java.util.zip.*;

public class TestZip {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
        
      try {
          int[] sizes = new int[]{1000,10000,100000,1000000,10000000, 1024*1024*20};
          Random r = new Random(System.currentTimeMillis());
          for(int i=0;i<sizes.length;i++){
              byte[] arr = new byte[sizes[i]];
              r.nextBytes(arr);
              //System.out.println("Beginning next round: " + arr.length);
              long start =System.currentTimeMillis();
              byte[] result = zipInputStream2("test", arr,1);
              System.out.println("size: " + arr.length + " time: " +  ((System.currentTimeMillis() - start)/1000.));
          }
          
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
    
    public static byte[] zipInputStream2(String entryName, byte[] arr, int level) throws IOException  {
        ByteArrayOutputStream myOut = new ByteArrayOutputStream();
        ZipOutputStream zipOut = new ZipOutputStream(myOut);
        
      //  zipOut.setLevel(level);
        
        zipOut.putNextEntry(new ZipEntry(entryName));
 
        zipOut.write(arr);
        zipOut.closeEntry();
        zipOut.close();
        
        
        return myOut.toByteArray();
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Rolling back to 1.5.0_02

Release Regression From : 5.0u6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION This issue has been fixed in 1.5.0_08 (and is not present in mustang). On solaris-amd64: jver 1.5.0_06 java -Xmx256m TestZip size: 1000 time: 0.086 size: 10000 time: 0.0010 size: 100000 time: 0.0080 size: 1000000 time: 0.102 size: 10000000 time: 1.094 size: 20971520 time: 2.244 jver 1.5.0_07 java -Xmx256m TestZip size: 1000 time: 0.129 size: 10000 time: 0.0010 size: 100000 time: 0.022 size: 1000000 time: 0.526 size: 10000000 time: 44.934 size: 20971520 time: 195.392 jver 1.5.0_08 java -Xmx256m TestZip size: 1000 time: 0.137 size: 10000 time: 0.0010 size: 100000 time: 0.015 size: 1000000 time: 0.108 size: 10000000 time: 1.135 size: 20971520 time: 2.345 jver 1.6.0 java -Xmx256m TestZip size: 1000 time: 0.128 size: 10000 time: 0.0010 size: 100000 time: 0.018 size: 1000000 time: 0.125 size: 10000000 time: 1.09 size: 20971520 time: 2.253 Similar results were observed on Windows XP
13-07-2006