Compiling to CIL Byte Code

This guide discusses the process of compiling queries and stylesheets to CIL byte code.

This topic contains the following sections.

Overview

The commercially licensed edition of XmlPrime provides the facility to compile XQuery and XSLT programs to CIL byte code. Byte code compilation has the potential to offer, for a modest increase in compilation time, greatly increased performance. However, the benefit depends greatly on the nature of the XQuery or XSLT program. In our experience, execution using byte code usually shows performance at least as good as non-byte code execution.

 
 
Note
Compilation to byte code is only available in the commercially licensed product.
 

Enabling Compilation to Byte Code.

The CodeGenerationCodeGenerationCodeGeneration property of the StaticContextSettingsStaticContextSettingsStaticContextSettings class can be set to DynamicMethodsDynamicMethodsDynamicMethods to enable compilation to byte code.

Performance with Byte Code.

We used the XTSpeedo XSLT benchmarking software to compare XmlPrime with byte code (XmlPrime-BC) enabled against a baseline of XmlPrime with byte code disabled (XmlPrime-S). With the "standard" test set, we see overall scores of 0.927 for file-to-file conversion, and 0.873 for tree-to-tree conversion, indicating an overall improvement in performance. This comes at a cost of compilation, which scores 1.313. However, at the extreme, we see the "xsltmark-dbonerow" taking approximately one fifth the time of the time of the (XmlPrime-S).

XTSpeedo graph showing the effect of byte code generation.

Looking at the XSLTmark tests, the overall scores are 0.868 and 0.679 for file-to-file and tree-to-tree respectively, demonstrating a clear win for byte code. However, the regular expression tests, which are dominated by calls into regular expression libraries, are essentially no faster with byte code. The "docbook-tests-001" test is perhaps most representative of real-world XSLT. Here the scores are 0.778 and 0.729, indicating roughly a 25% reduction in execution time. The XMark tests generally only show a modest improvement, however in many of these test cases, the actual time spent performing the transformation is very little in comparison with the time taken to load the input document. This can be observed in test "xmark-q1-1", where the tree-to-tree time is less than two thousandths of the file-to-file time.

The general advice is to benchmark you XSLT with and without byte code compilation. Depending on your particular use case, slower compilation may outweigh faster execution. However, if you are compiling a query or stylesheet to use repeatedly, the greater execution speed may quickly dominate over compilation time. It may be, as is the case in many of the XTSpeedo test cases, that loading the input documents dominates the overall processing time.