Nov
13th
2004
Sat
13th
2004
Java XPath 1.0 Engine Comparison - Performance
The Tests:
- 230k source XML - Romeo and Juliet
- Expression test suite - Includes: Context expression, test expression and expected result
The Results: Each test executed 10x. J2SE 1.5. Intel 2.4Ghz. Results in milliseconds. Grey boxes are compliance failures.
General Performance Observations
- Navigating the descendant axis is slow - Expressions that included descendant axis traversal tend to be quite slow.
- Function evaluation is fast - Expressions that include no node traversal were in general quite fast.
- Explicit path select is fast - Expressions that spell out the path to desired nodes are in general quite fast.
Library Specific Observations
- J2SE 1.5 and Xalan - These are the same engines. Sun wraps Xalan with a thin facade ( com.sun.org.apache.xpath.internal ). Performance and compliance was good. What you would expect from a mature library.
- Jaxen - Slowest of the bunch. Mostly attributable to descendant axis traversal. Hope? http://jira.werken.com/browse/JAXEN-31
- JXP - Speed is it’s proposed value proposition. While it’s not the slowest, it’s not the fastest either. Perhaps the time sink is in node retrieval and not traversal ( sum(//act/@id) took 15ms but //* took 2797ms )
- JXPath - Reasonable performance. Does not like ancestor-or-self::*.
- Resin - Wicked fast under certain circumstances ( //* in 63ms ! ). Extremely slow under others ( //line | //speaker in 5265ms ! ).
- Saxon - Good performance. following-sibling traversal a bit slow.
Some take aways:
- Measure your expression execution early and often; don’t assume.
- Don’t get lazy. Avoid descendant navigation if you know the path to the nodes you are looking for.
- Function evaluation is fast. Don’t be afraid to use them. Don’t overlook your XPath engine if your app needs simple expression evaluation.
Sidebar: Seems like a cross library / platform performance test suite could be created. A java specific harness could also be crafted to save some double effort and promote performant implementations.
