• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Improving XPath evaluate performance

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic