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

json lib is slow on Linux 64 Java 8

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      2.6.32-279.22.1.el6.x86_64

      A DESCRIPTION OF THE PROBLEM :
      Parsing of a large json using json lib is 3 to 6 times slower to run Java 8 compared to Java 6 on a 64 bit Linux machine.

      REGRESSION. Last worked in version 8u60

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Parse a large json file using jsonlib: http://json-lib.sourceforge.net/

      On a linux 64 machine running it on Java SE 8 is 3 to 6 times slower than Java SE 6. The example at the end took 10 seconds on Java 6 and 30 seconds on Java 8.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The performance should be identical on Java 6 and 8.
      ACTUAL -
      Java SE 8 is 3 to 6 times slower than Java SE 6.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayOutputStream;
      import java.io.FileInputStream;
      import java.io.InputStream;

      import net.sf.json.JSONObject;


      public class JsonLib {
          public static void main(String [] args) throws Exception {
              String jsonPath= "sample.json";
              if (args.length > 0) {
                  jsonPath= args[0];
              }
              byte [] b = new byte[2048];
              int len;
              ByteArrayOutputStream bop = new ByteArrayOutputStream(8192);
              InputStream ip = new FileInputStream(jsonPath);
              while ((len = ip.read(b)) > 0) {
                  bop.write(b, 0, len);
              }
              ip.close();
              String countryJson = new String(bop.toByteArray());
              long start = System.currentTimeMillis();
              for (int i = 0; i < 50; i++)
              JSONObject.fromObject(countryJson);
              long end = System.currentTimeMillis();
              System.out.println("JSON PARSE TIME = " + (end - start));
          }
      }

      Below is a list of jar files required. I can send/upload them and the sample json if needed.

      json-lib-2.2.1-jdk15.jar"
      commons-logging.jar
      ezmorph-1.0.4.jar
      commons-lang-2.3.jar
      commons-beanutils-1.7.0.jar
      commons-collections-3.2.jar
      junit-4.4.jar

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

      CUSTOMER SUBMITTED WORKAROUND :
      After hitting this issue we have moved from jsonlib to jackson for parsing.

        1. commons-beanutils-1.7.0.jar
          184 kB
        2. commons-collections-3.2.jar
          558 kB
        3. commons-lang-2.3.jar
          240 kB
        4. commons-logging.jar
          37 kB
        5. ezmorph-1.0.4.jar
          84 kB
        6. JsonLib.java
          1 kB
        7. json-lib-2.2.1-jdk15.jar
          137 kB
        8. junit-4.4.jar
          158 kB
        9. README.txt
          0.7 kB
        10. sample.json
          254 kB
        11. set_classpath.sh
          0.1 kB

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: