"Boysko, Glenn" wrote:
> I'm afraid that I don't know the internals of the Xalan code well
> enough
> to reply. Our code is a Java class that makes repeated (sometimes up
> to
> 1000) calls to XPathAPI.selectSingleNode() in the same thread. Is
> that a
> single transform? A single transformers? In this single Java
> instance
> the DOM is the same throughout. I realize that this is inefficient
> right
> away (as our implementation should record those key nodes and reuse
> their
> positions instead of re-finding them each time).
>
> Would you be able to recommend a way to optimize this case, perhaps
> using
> some lower-level APIs/classes? In our scenario, the class is
> converting
> a DOM tree into HTML using selectSingleNode and selectNodes.
Glenn --
When I mentioned transforms, this refers to using XSLT with XalanJ.
Apparently, you're not using the XSLT, just the XPath support so the
transforms comment doesn't apply.
The XPathAPI is really designed as a demonstration and for low volume
use. It creates a new XPathContext and XPath every time that
selectSingleNode is called. Are you specifying a different XPath every
time or are you using the same XPath? If you're using the same one, you
can build the XPath once and just keep reusing it. The XPathContext()
needs to be created for each thread but only once. You can call reset()
after each use to prepare it for the next iteration.
Have a look at the code inside XPathAPI which is not big. You can
restructure your application to build the XPath and XPathContext only
once per thread and then serially resuse them as needed without having
to recreate them. The XPath object does not contain any runtime state
so it can safely be shared across threads.
Gary