Activate your free membership today | Log-in

Friday, February 27th, 2009

Ghosts in the machine – avoid using window.sun in Firefox as it starts the Java engine!

Category: Java, JavaScript, Mozilla

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.

Posted by Chris Heilmann at 2:18 am
7 Comments

+++--
3.7 rating from 16 votes

7 Comments »

Comments feed TrackBack URI

about:mozilla anyone? :)

Comment by sixtyseconds — February 27, 2009

I believe, the performance of Java Applet hundends times faster than Javascript.

The only performance problem with Java Applet- it’s startup time.

Comment by kazukin — February 27, 2009

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.

Comment by Snyke — February 27, 2009

“…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. :)

Comment by MichaelThompson — February 27, 2009

@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.

Comment by TNO — February 27, 2009

I would call that a smaller truth since it’s a microbenchmark.

Comment by ilazarte — March 2, 2009

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.

Comment by TNO — March 2, 2009

Leave a comment

You must be logged in to post a comment.