When JavaScript Equals Java in Speed

I can remember back in the mid 1990’s when Java first came out and was quickly dismissed as being a major player in the IT world. This was going to happen despite Java’s cross platform capabilities and rich set of standard libraries because Java was a slow, interpreted language. Maybe on the Web Java could succeed because a) of its dynamic functionality and b)the prevalence of network delays would allow Java apps to have the “apparent” speed of C, C++, Cobol, Delphi, Fortran and other hard-coded and compiled languages and associated applications.

Well its 15 years later and Java has become the language of choice for BI, and major cross platform server apps. Meanwhile, JavaScript is the Cloud and Web Language of the day – though Apex, PHP, Perl, Python, Ruby, Groovy and other interpreted languages used on both Web and desktop apps would argue about how commanding the leadership position of JavaScript really is. But JavaScript is also discounted as a serious language because a)its interpreted and b)has a number of security gaps/weaknesses such as eval function, lax try/catch error trapping [the syntax is there but use falters] and open [instead of default encrypted] JSON/XML metadata for data interoperability. Even Google has resorted to its Go language as a more robust alternative to JavaScript in certain contexts.

But JavaScript continues to evolve rapidly as one of the key drivers of Web 2.0 and agile AJAX apps. Security and reliability with RESTful apps can be built with JavaScript. And so attention is shifting to JavaScript’s speed and performance. And a first glance at the Java versus JavaScript benchmarks from 2008 does not bode well for JS:

A first glance shows SpiderMonkey running at an average of 50 times slower than a Java 6 client. Java also gives away memory-size comparisons being on average 6 times bigger than the corresponding running Java code. However, the code size for JavaScript is notably smaller – about 2/3rd the size of the corresponding Java programs.

On the other side of the fence SpiderMonkey is no longer the state of the art in JavaScript implementations. And of course, Google, Mozilla, Opera and Apple are working fulltime on improving their JavaScript engines. Notably, Microsoft is not investing in its JavaScript engine but rather is devoting all speed improvements to its proprietary [must run in Windows best] CLR and Silverlight code [this may change with IE9 showing JS speed upgrades]. However, the key point here is that the benchmark numbers shown above are reminiscent of Java versus C/C++ when Java was starting out. Can JavaScript start to challenge Java speeds?

Well the improvements in ActionScript’s perfromance by Adobe gives a hint of what to expect. Every version of ActionScript [which was at first just JavaScript syntax with larger media libraries and now is ECMAScript 4 syntax – the scheduled next rev of JavaScript] for the past 5 version updates has always seen a notable speed improvement. The improvements in TraceMonkey speed noted here [an average of 8x speedier] are examples of what can be done with JavaScript. Several reports of JS speed improvements from Google, Mozilla , and Opera are typical.

Hence I am willing to go on record and say when JavaScript starts to match Java speeds – how does that change the Web and Mobile Device scene? Already, without a great UI IDE or design tool, JavaScript dominates Java in development of Web 2.0 interfaces. Will this extend to broader apps? Palm with its webOS is betting that is so. So is Google in effect doing the same with its Chrome OS. Where does that leave Apple’s proprietary Objective C for iPhone and iPad or Microsoft’s proprietary CLR and Silverlight [note that Mono which powers CLR and Silverlight on MacOS and Linux is about 1.5 versions behind the native .NET CLR on Windows]?

But Java you say will continue to improve in speed. Maybe. But maybe not so fast as Oracle spends more on incorporating Java into its own database and application framework. So if history repeats itself, Web and Mobile developers that use standards like HTML4 & 5, DOM, CSS, XML and JavaScript will likely find themselves having not only the most open but also the most cross platform ready and fastest development tools.