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

XMLReaderFactory.createXMLReader is very slow

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 1.4.0
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.4
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Backports

        Description

        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 ----------

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: