Tony Coates relates an incident in which he found a Java-based implementation to be at least ten times faster than a native-code implementation. He concludes that native code solutions “can no longer claim an automatic performance advantage”.
He states in a little more detail:
What does this all mean? Well, I’m not suggesting that Java programs are always faster now than their native code equivalents. That isn’t the case. What I am suggesting is that it is no longer valid to assume that native code solutions are faster than Java (or other virtual machine) solutions. Some solutions will be faster than others, but you won’t know if native code is faster or slower than virtual machine code now without actually testing it. That is a significant change, which impacts the way architectural technology choices are made for projects.
I think he might probably have chosen a bit of a better example to illustrate his point. What he actually compared was a XSLT 2.0 test case, and the implementations he tested were XML Spy (C or C++ code, I assume) and Mike Kay’s Saxon 8.
First off, given that Mike Kay was the editor for the XSLT 2.0 spec and that he literally “wrote the book” (his XSLT Programmers Reference) on both XSLT 2.0 and XSLT 1.0 and that Saxon 8 can basically be considered the reference implemenation for the XSLT 2.0 spec, it ain’t too surprising to find out that it significantly outperforms a native-code implementation in another application.
And I would suspect that another possible factor is that the XSLT 2.0 implementation in XML Spy may just not be particularly well written. Hard to check though, since it’s proprietary code. And we lack an open-source C or C++ implementation of XSLT 2.0 to do any comparing with. If we did — if, say, Daniel Veillard (the principal developer of libxml2 and libxslt) were to decide to write an XSLT 2.0 implementation — I reckon that implementation might also end up being a helluva lot faster than the XML Spy implementation.
I don’t know how many smart people were ever given to
just “assuming” that native code solutions are always faster than Java-based (or other VM-based) solutions. But I think most have seen from experience that a well-written natively compiled application, especially one written in C, is likely to be measurably faster than an equally well-written implementation in Java.
Time to finally give up and write everything in Java?