In my project, every call to retrieve a string had to evaluate an XPath expression on the XML configurations DOM tree. In a scenario of 300 concurrent users this caused a normal 50ms operation to take up to 500 ms. Nearly 10 times of slowdown. This caused us to look for improvement. Our approach was caching, but currently there is no support for cached configurations. So we built our own. You'll find the code in the attached Gist.

What to cache

Our approach was first to use an CGlib Method invocation interceptor, but this caused the same slow down due to heavy operation overhead by CGlib. The next approach was to cache SubnodeConfiguration and the outcome of getProperty. And this way it helped us to speed up the configuration access times by factor 4. Take a look at the comparison:


Lower is better, all values in milliseconds.

This approach allows efficiently to access configuration at different hierarchy levels, support for reloading configuration and value interpolation (for e.g. system property placeholder support).