Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7075474

XMLEncoder take 7 times longer to encode an Object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • client-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java 1.6.0_26
      and
      java 1.7.0


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Pro Service Pack 3

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Intel Core 2 CPU
      1.66Ghz
      3 Go RAM

      A DESCRIPTION OF THE PROBLEM :
      We use XMLEncoder a lot in our application to serialize object on disk.
      We are testing java 1.7, and we have seen a major increase in serialization time.
      (For dezerialization there is no problem).

      We have created a test case. When we run it in java 1.6 we get the expected result and when we run it in java 1.7 we get the actual result.

      We see there is a x7 increase.

      REGRESSION. Last worked in version 6u26

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      serialization = 1297
      deserialization = 750
      ACTUAL -
      serialization = 7390
      deserialization = 375

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class SerialTest {

      private HashMap<String, Double> dataMap;

      public static ExceptionListener currentListener = new ExceptionListener() {
      public void exceptionThrown(Exception e) {
      e.printStackTrace();
      }

      };

      /**
      *
      */
      public SerialTest() {
      this.dataMap = new HashMap<String, Double>();
      }

      /**
      * @return the dataMap
      */
      public HashMap<String, Double> getDataMap() {
      return this.dataMap;
      }

      /**
      * @param dataMap the dataMap to set
      */
      public void setDataMap(HashMap<String, Double> dataMap) {
      this.dataMap = dataMap;
      }

      /**
      * @param size
      */
      public void fillDataMap(int size) {
      Random rand = new Random();
      for (int i = 0; i < size; i++) {
      this.dataMap.put("data " + i, rand.nextDouble());
      }
      }

      /**
      * @param args
      */
      public static void main(String[] args) throws Exception {
      SerialTest serial = new SerialTest();
      serial.fillDataMap(10000);
      File target = new File("test.xml");
      target.delete();
      if (!target.exists()) {
      target.createNewFile();
      }
      long time = System.currentTimeMillis();
      FileOutputStream fileStream = new FileOutputStream(target);
      BufferedOutputStream stream = new BufferedOutputStream(fileStream);
      XMLEncoder encoder = new XMLEncoder(stream);
      encoder.setExceptionListener(SerialTest.currentListener);
      encoder.writeObject(serial);
      stream.flush();
      fileStream.flush();
      encoder.close();
      stream.close();
      long end = System.currentTimeMillis();
      System.out.println("serialization = " + (end - time));

      time = System.currentTimeMillis();
      XMLDecoder decoder = null;
      decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(target)));
      decoder.setExceptionListener(SerialTest.currentListener);
      SerialTest result = (SerialTest) decoder.readObject();
      System.out.println("size of map " + result.dataMap.size());
      decoder.close();
      end = System.currentTimeMillis();
      System.out.println("deserialization = " + (end - time));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I am trying to copy the source code of XMLEncoder of java 1.6 to create a custom class. But the code contains a lot of private or invisible methods.

            malenkov Sergey Malenkov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: