GeeCON Prague 2014*
The moose likes Performance and the fly likes Improving XPath evaluate performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Performance
Bookmark "Improving XPath evaluate performance" Watch "Improving XPath evaluate performance" New topic
Author

Improving XPath evaluate performance

Paulo Carvalho
Ranch Hand

Joined: Nov 12, 2008
Posts: 57
Hello

I have a Java program that read and evaluate an XML inputSource using javax.xml.xpath.XPathExpression class. The function used for that is the following one:



It works fine but I would like to improve the performance because an important time is spend for doing this kind of treatment when it the function is called many times.

Any one knows another way to do the same but with better performance results?

Thanks

regards
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3016
    
  10
Probably you need to first find out which parts of the method are taking the most time. I suggest using a profiler, or a monitor like JAMon. There's little point spending time in optimizing the wrong parts of the program.

When you call this function many times, are the arguments completely different each time? Or do they often repeat? Does the function get called many times with the same xpathQuery, but different source? Or perhaps there are a few different values for xpathQuery, but those values are used many times for different sources? If so, you may be able to benefit from precompiling a limited number of XPathExpression objects, so you don't have to keep recompiling the same expressions. But note that if you're calling the method from multiple threads, there are additional complications. You have to make sure that each XPathExpression is only used by one thread at a time.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
I found that creating an XPath expression object was very fast compared to applying it. Also the memory used is small.

XPath will always be much much slower than applying the org.w3c.dom methods.

Bill
 
GeeCON Prague 2014
 
subject: Improving XPath evaluate performance