Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > XML applications > Use the XML API to perform operations > Performing basic operations
Choosing between the compiler and the interpreter
We can use either the compiler and the interpreter for preparing and executing an XQuery expression, XPath expression, or XSLT stylesheet. Choosing which one to use is very application specific and depends on several factors.
This article is about choosing between the compiler and interpreter when you are preparing the expression, query, or stylesheet during the application run time.
Expressions, queries, and stylesheets can also be prepared ahead of time (precompiled). This is the most efficient option because the preparation is done ahead of time instead of during the application run time, but precompiling might not be applicable to all applications. See the articles related to precompiling for more details.
Procedure
Use the setUseCompiler(true) method on the XStaticContext to use the compiler, and use the setUseCompiler(false) method to use the interpreter.
The default is to use the interpreter for preparing an XQuery expression, XPath expression, or XSLT stylesheet.
It takes longer to prepare a compiled executable than an interpreted executable, but a compiled executable generally runs faster; therefore, there is a trade off between the cost of preparing a compiled executable and the improved execution-time efficiency.
Differences between using the compiler and the interpreter.
Consider these factors when choosing between compiling and interpreting.
Factor Description Number of input documents that the executable will be used to process If the executable will be used only to process a few input documents, it might not be worth the extra time needed to create a compiled executable because the improved efficiency of the executable might not make up for the extra prepare time. If the executable will be used to process many input documents, it might be worth the extra prepare time. Size of the input documents Larger input documents take longer to process; therefore, it might be worth the extra prepare time to create a compiled executable in order to get a more efficient executable object to handle the larger documents. Size of the expression, query, or stylesheet It takes longer to prepare a larger expression, query, or stylesheet; therefore, this affects the preparation time and execution time trade off.
Example
// Create a new XFactory XFactory factory = XFactory.newInstance(); // Create a new XStaticContext XStaticContext staticContext = factory.newStaticContext(); //Use the compiler sc.setUseCompiler(true); //Use the interpreter sc.setUseCompiler(false);
Precompile using the command-line tools
Precompile in Java