First of all, I would place those setProperty calls in a static initializer
so you don't call them each time.  Also, realize that it will always take
some time the first time you create a factory and/or builder.

If you run your test "n" times, you should find it much faster on average
with the system properties set.


-----Original Message-----
From: Jos van den Oever [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 14, 2005 7:35 AM
To: [EMAIL PROTECTED]
Subject: Re: dom build speed

Hallo Rick,

Thanks for your reply. I added your suggested lines to the code, but I see
no 
speed increase at all. Just to make sure, here's the code I use for parsing 
now:

   if (docbuilder == null) {
    System.setProperty("javax.xml.transform.TransformerFactory",
      "org.apache.xalan.processor.TransformerFactoryImpl");
    System.setProperty("org.apache.xml.dtm.DTMManager",
      "org.apache.xml.dtm.ref.DTMManagerDefault");
    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");
    DocumentBuilderFactory factory = DocumentBuilderFactory
      .newInstance();
    System.out.println(factory);
    factory.setNamespaceAware(true);
    factory.setValidating(false);
    factory.setExpandEntityReferences(false);
    docbuilder = factory.newDocumentBuilder();
    docbuilder.setErrorHandler(errorHandler);
    System.out.println(docbuilder);
   }
   InputSource is = new InputSource(rwm);
   // output that measures the DOM parse time
   long t = System.currentTimeMillis();
   doc = docbuilder.parse(is);
   t = System.currentTimeMillis()-t;
   System.out.println("parseTime: "+String.valueOf(t));

Could the DOCTYPE declaration have anything to do with it?

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>

Cheers, Jos

PS, parsing the file with the qt library takes ~7 ms...

On Monday 14 February 2005 13:14, Rick Bullotta wrote:
> Add these system properties to your code and you may see a DRAMATIC
> increase in performance in DOM creation as well as Xpath and Transformer
> creation. Using this technique bypasses a lot of very expensive factory
> overhead which involves searching in the JAR file and the classpath for
> configuration information.
>
> // Xalan
>
> System.setProperty("javax.xml.transform.TransformerFactory",
> "org.apache.xalan.processor.TransformerFactoryImpl");
>
> System.setProperty("org.apache.xml.dtm.DTMManager",
> "org.apache.xml.dtm.ref.DTMManagerDefault");
>
> // Xerces
>
> 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: Jos van den Oever [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 14, 2005 6:56 AM
> To: [EMAIL PROTECTED]
> Subject: Re: dom build speed
>
> > I've run up against this problem as well.  If I'm not mistaken, the
> > problem is the way Xerces handles setting properties on a DOM parser
> > via the JAXP interfaces.  Xerces will create a new instance (!) of the
> > DOMParser class for every single property you set (i.e., via
> > setValidating(), setNamespaceAware(), etc.).  This wouldn't be so bad
> > if it wasn't so expensive to create a DOMParser instance, but it is.
> > You should really be timing the parse and not the setup and parse.
> >
> > I was sort of shocked when I first discovered how poorly Xerces
> > handles setting JAXP DocumentBuilder properties, but from
> > conversations on this mailing list it's obviously a known problem and
> > there doesn't seem to be much that can be done about it.  Shrug.
>
> Hello Curtis,
>
> What I didn't mention: I'm reusing the DocumentBuilder and this gives me
> only
> a small speedup. What I'm timing is the parsing itself, not the creation
of
> the DocumentBuilder. Even if creating the DocumentBuilder was really slow,
> it
> wouldn't really be a problem because I'm using it in a Bean and it's only
> created once per Bean.
>
> Cheers, Jos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to