• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Improving XPath evaluate performance

 
Paulo Carvalho
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic