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

XMLReaderFactory.createXMLReader is very slow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 6
    • xml
    • 1.4
    • x86
    • windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.6.0_13"
        Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
        Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Windows XP SP2

        A DESCRIPTION OF THE PROBLEM :
        org.xml.sax.helpers.XMLReaderFactory.createXMLReader () contains some very slow code.

        If no classname is set as a system property, then the code underneath line 114 ("2. if that fails, try META-INF/services/") gets run. This gets the resource as stream and reads it in _every_ time that createXMLReader is called!

        I changed the implementation of createXMLReader so as to cache the classname once it has been found the first time. This resulted in a 10-fold speed increase for my simple test case that calls MLReaderFactory.createXMLReader () 10,000 times.



        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import org.xml.sax.helpers.XMLReaderFactory;

        public class XMLReaderTest {

          public static void main(String[] args) {
            try {
              int times = 10000;
              long start = System.currentTimeMillis();
              for(int i=0;i<times;i++) {
                XMLReaderFactory.createXMLReader();
              }
              long end = System.currentTimeMillis();
              double speed = ((end-start));
              System.out.println(speed+"ms");
            } catch (Throwable e) {
              e.printStackTrace();
            }
          }
        }

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

              joehw Joe Wang
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: