Improving XQuery performance

XQuery transformations are often used in pipelines in Oracle Service Bus to perform data transformation.  Performance of XQuery transformations is a key area to focus on when performance tuning an Oracle Service Bus environment.

During performance testing of your project you should use the activity timing metrics to identify any XQuery performance issues and optimize those queries for better performance.  The recommended approach is to measure the average time taken to run each query, then multiply this by the number of times you expect that query to be used over some defined time period, e.g. one hour.  The results should be sorted from largest to smallest.  You should start at the top of the list and optimize as many of the queries as necessary to obtain the necessary performance.  You should only optimize the queries if there is likely to be a significant performance gain.  Optimization of the queries should be done by looking for opportunities to reorder or modify the statements in order to obtain faster execution.

XQuery performance should be tested with large payloads whenever possible, or at least with many invocations of the same transformation and results averaged.

Some general quidelines for improving the performance of XQuery transformations are as follows:

  • Avoid the use of double slashes (“//”) at the beginning of XPath expressions.  They should only be used if the exact location of a node is not known at design time.  Use of “//” will force the entire payload to be read and parsed.
  • Index XPath expressions where applicable.  For example, if you know that there is only one “Order” and only one “Address” then using an XPath expression like “$body/Order[1]/Address[1]” instead of “$body/Order/Address” will minimize the amount of the payload that needs to be parsed.  Do not use this approach if the expected return value is a list of nodes.
  • Extract frequently used parts of a large XML document as intermediate variables.  This will consume more memory, but will reduce redundant XPath processing.  For example:
    let $customer := $body/Order[1]/CustomerInfo[1]
    $customer/ID, $customer/Status

About Mark Nelson

Mark Nelson is an Architect in the Enterprise Cloud-Native Java Team at Oracle. Mark works mainly on making Java (traditional and microservices) easy to use in Kubernetes and the CNCF ecosystem. Before joining this team, Mark worked on Wercker, WebLogic and was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s