-
Bug
-
Resolution: Fixed
-
P3
-
6
-
1.4
-
x86
-
windows_xp
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2207333 | 7 | Joe Wang | P3 | Closed | Fixed | b112 |
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 ----------
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 ----------
- backported by
-
JDK-2207333 XMLReaderFactory.createXMLReader is very slow
- Closed