Friday, February 27th, 2009
Ghosts in the machine – avoid using window.sun in Firefox as it starts the Java engine!
Sometimes you find leftovers of old technology in browsers that blow your mind. One of these “ghost in the machine” problems exists in Firefox: if you use window.sun or function sun() in JavaScript you effectively start the Java VM.
There are a few “magic” properties on Mozilla’s DOMWindow interface for supporting LiveConnect that will initialize the Java plugin and all the baggage that comes with it (which, with modern Java plugins, means launching java.exe as a subprocess). Looking up these properties on the window object is all it takes.
There are a few more of these still in the Mozilla source code and they are part of the old Netscape LiveConnect engine. They are:
- java
- Packages
- netscape
- sun
- JavaClass
- JavaArray
- JavaMember
Avoid these at all cost lest you want the performance of your JavaScript to be like a Java Applet.












about:mozilla anyone? :)
I believe, the performance of Java Applet hundends times faster than Javascript.
The only performance problem with Java Applet- it’s startup time.
I have to agree with kazukin. Too bad the JVM has to be started at each plugin object once, otherwise we’d had Ajax with Java instead of Javascript.
“…means launching java.exe as a subprocess.”
Oddly, my Mac doesn’t seem to do this. Nor does my Linux VM. Hmm…I must be doing something wrong. :)
@kazukin:
no need to exaggerate, stats speak a larger truth:
JavaFX vs JavaScript
.
related post
.
once Firefox begins to trace through recursion, their numbers will drop significantly as well.
I would call that a smaller truth since it’s a microbenchmark.
Regardless, its still a valid statistic refuting the claim of a “hundred times faster”. Hopefully the Language Shootout website will update its graphs for the bigger truth you’re hoping to see, and include the V8 engine in its statistics.