A progress report on query compilation: I've now got to the point where I can compile the knight's tour query (tour.xq in the Saxon samples distribution) into Java code, and execute it with correct results. It's running in 39.3ms, compared with 45.9ms for the interpreted code, which isn't wildly exciting, but there's enormous scope for tuning the generated code and it shouldn't be hard to improve on this figure very significantly.
The 292 lines of XQuery translate into 1362 lines of Java, which will come down as the code generation gets more efficient.
This is of course a very untypical query, as it has no input and generates fairly minimal output: it spends most of its time doing recursive function calls. But it's always been something of a torture test, so it's pleasing to have got it working (without any really hard bugs to solve en route, I might add). I've also got most of the XMark benchmark queries working, with speed factors varying from about 110% (compiled-to-interpreted throughput ratio) to 400%.
There's still an enormous amount of work ahead though. Compiling 30% of the language is enough to run 90% of queries, but it's not enough for a release.
|
|
||||||||
Compiling the Knight's Tour
Comments
Re: Compiling the Knight's Tour
by
Michael Allman
on Wed 11 Oct 2006 19:56 BST | Permanent Link
Compiling XQuery expressions to Java bytecode is on my list of pet projects. I'm excited to hear you're working on it. I haven't started my own work, and I may never get to it myself, especially if you're working toward integration with a future release of Saxon.
BTW, am wondering what you're using to write bytecode. I was planning to use ASM. Good luck, and hope to see the fruits of your labor. Re: Re: Compiling the Knight's Tour
In the first phase I'm generating Java source code and putting it through the Java compiler. A bit clunky, but I reckon the Java compiler probably generates better code that I could achieve, and it's certainly a lot easier to debug. More importantly, it's easier for me to see what I'm generating and hence to improve the generated code. In some ways I think it also gives more flexibility in the way the code is deployed.
Re: Re: Re: Compiling the Knight's Tour
by
Michael Allman
on Thu 12 Oct 2006 21:45 BST | Permanent Link
I remember another reason I wanted to write bytecode directly --- I wanted to compile queries dynamically, at runtime. I bet you're compiling ahead of time. I wanted to build something that could perform reasonably well as a drop-in replacement for the current Saxon query "compiler".
Re: Compiling the Knight's Tour
By the way, I should mention that I've now got the elapsed time down to 12.2 ms. Further optimization is possible, but it's probably time to move on to study some more typical queries. The target is to double execution speed for the "average" query if there is such a thing.
Re: Compiling the Knight's Tour
Further progress: After spending some time getting the W3C XQuery test suite to run in compiled mode (which it now does, bar a couple of dozen tests) I've returned recently to the Knight's Tour, and now have the execution time down below 8.9ms. The size of the Java code generated is now 778 lines.
|
Search
Recent Comments
Recent Articles
Month Archive
|
|||||||