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.