You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Curtiss Howard <cu...@gmail.com> on 2004/12/17 16:01:50 UTC

Xerces2 DocumentBuilderFactory.setAttribute() is very slow

I was profiling some code recently and found that the Xerces2's JAXP
DocumentBuilderFactory setAttribute() method is very slow on my
machine (Athlon XP 2500+, 1GB RAM).  It takes approximately 50ms (!)
to call setAttribute(), which I do about five times when setting up my
DocumentBuilderFactory.  I realize that in terms of long-running
applications this overhead is negligible, but in the case of
short-lived applications (of which I intend to do), it is quite
noticeable.

I glanced through
org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.java and it looks
like the culprit is the manner in which features/properties are
checked for correctness: an instance of DOMParser is created and the
feature/property is passed to it.  This wouldn't be a bad thing if the
cost of creating a DOMParser wasn't, relatively speaking, so
expensive.

I'm throwing this issue out on the user mailing list because I'm not
sure if it would be appropriate to mention it on the developer list. 
At any rate, is anyone aware of this issue?  Is anything being done to
address it?  If not, would I be able to submit my own patch for the
problem?


Thanks,


Curtiss Howard

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Xerces2 DocumentBuilderFactory.setAttribute() is very slow

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
The problem here is that the factory knows nothing about the parsers it 
creates yet is required to throw an exception if the attribute specified 
isn't recognized. This is why it creates one each time you set an 
attribute on the factory. It's really ugly though I don't see a way around 
it. A different parser configuration could be selected at any point 
completely changing which features/properties are recognized.

Curtiss Howard <cu...@gmail.com> wrote on 12/17/2004 10:57:10 AM:

> On Fri, 17 Dec 2004 10:31:57 -0500, Rick Bullotta
> <ri...@lighthammer.com> wrote:
> > Yup.  It's a concern.  Best way around it we've found is to set a 
bunch of
> > system properties to shortcut the factory creation process as in:
> > 
> > System.setProperty("javax.xml.transform.TransformerFactory",
> > "org.apache.xalan.processor.TransformerFactoryImpl");
> > System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
> > "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
> > System.setProperty("javax.xml.parsers.SAXParserFactory",
> > "org.apache.xerces.jaxp.SAXParserFactoryImpl");
> > 
System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
> > "org.apache.xerces.parsers.XML11Configuration");
> > 
> > Rick Bullotta
> > CTO
> > Lighthammer Software (http://www.lighthammer.com)
> > 
> 
> Rick,
> 
> Thanks for the reply.  I'm not sure if this is my problem though --
> I've not seen speed issues with creating the DocumentBuilderFactory,
> but rather in setting features/properties such as
> 
> http://java.sun.com/xml/jaxp/properties/schemaLanguage,
> http://java.sun.com/xml/jaxp/properties/schemaSource,
> http://apache.org/xml/properties/internal/grammar-pool,
> etc.
> 
> (BTW, I realize that I am setting some Xerces-specific properties
> while at the same time trying to use JAXP interfaces.  My problem
> would go away if I were to use only Xerces's DOMParser/SAXParser
> classes, but I don't want to tie myself to a specific parser library).
> 
> 
> Curtiss Howard
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Xerces2 DocumentBuilderFactory.setAttribute() is very slow

Posted by Curtiss Howard <cu...@gmail.com>.
On Fri, 17 Dec 2004 10:31:57 -0500, Rick Bullotta
<ri...@lighthammer.com> wrote:
> Yup.  It's a concern.  Best way around it we've found is to set a bunch of
> system properties to shortcut the factory creation process as in:
> 
> System.setProperty("javax.xml.transform.TransformerFactory",
> "org.apache.xalan.processor.TransformerFactoryImpl");
> System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
> "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
> System.setProperty("javax.xml.parsers.SAXParserFactory",
> "org.apache.xerces.jaxp.SAXParserFactoryImpl");
> System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
> "org.apache.xerces.parsers.XML11Configuration");
> 
> Rick Bullotta
> CTO
> Lighthammer Software (http://www.lighthammer.com)
> 

Rick,

Thanks for the reply.  I'm not sure if this is my problem though --
I've not seen speed issues with creating the DocumentBuilderFactory,
but rather in setting features/properties such as

http://java.sun.com/xml/jaxp/properties/schemaLanguage,
http://java.sun.com/xml/jaxp/properties/schemaSource,
http://apache.org/xml/properties/internal/grammar-pool,
etc.

(BTW, I realize that I am setting some Xerces-specific properties
while at the same time trying to use JAXP interfaces.  My problem
would go away if I were to use only Xerces's DOMParser/SAXParser
classes, but I don't want to tie myself to a specific parser library).


Curtiss Howard

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


RE: Xerces2 DocumentBuilderFactory.setAttribute() is very slow

Posted by Rick Bullotta <ri...@lighthammer.com>.
Yup.  It's a concern.  Best way around it we've found is to set a bunch of
system properties to shortcut the factory creation process as in:

System.setProperty("javax.xml.transform.TransformerFactory",
"org.apache.xalan.processor.TransformerFactoryImpl");
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", 
"org.apache.xerces.parsers.XML11Configuration");

Rick Bullotta
CTO
Lighthammer Software (http://www.lighthammer.com)

-----Original Message-----
From: Curtiss Howard [mailto:curtiss.howard@gmail.com] 
Sent: Friday, December 17, 2004 10:02 AM
To: xerces-j-user@xml.apache.org
Subject: Xerces2 DocumentBuilderFactory.setAttribute() is very slow

I was profiling some code recently and found that the Xerces2's JAXP
DocumentBuilderFactory setAttribute() method is very slow on my
machine (Athlon XP 2500+, 1GB RAM).  It takes approximately 50ms (!)
to call setAttribute(), which I do about five times when setting up my
DocumentBuilderFactory.  I realize that in terms of long-running
applications this overhead is negligible, but in the case of
short-lived applications (of which I intend to do), it is quite
noticeable.

I glanced through
org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.java and it looks
like the culprit is the manner in which features/properties are
checked for correctness: an instance of DOMParser is created and the
feature/property is passed to it.  This wouldn't be a bad thing if the
cost of creating a DOMParser wasn't, relatively speaking, so
expensive.

I'm throwing this issue out on the user mailing list because I'm not
sure if it would be appropriate to mention it on the developer list. 
At any rate, is anyone aware of this issue?  Is anything being done to
address it?  If not, would I be able to submit my own patch for the
problem?


Thanks,


Curtiss Howard

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org