views:

2869

answers:

8

At a recent discussion on Silverlight the advantage of speed was brought up. The argument for Silverlight was that it performed better in the browser than Javascript because it is compiled (and managed) code.

It was then stated that this advantage only applies to IE because IE interprets Javascript which is inefficient when compared to that of other browsers such as Chrome and FireFox which compile Javascript to machine code before execution and as such perform as well as Silverlight.

Does anybody have a definitive answer to this performance question. i.e. Do/will Silverlight and Javascript have comparable performance on Chrome and Firefox?

+4  A: 

Javascript is ran in a virtual machine by most browsers. However, Javascript is still a funky language, and even a "fast" virtual machine like V8 is incredibly slow by modern standards.

I'd expect the CLR to be faster.

FlySwat
ECMAscript isn't all that 'funky'. It's a very decent C-style functional language, the buggered browser DOM just gives it a bad name.
Internet Friend
it's not only DOM (but it's the worst) there are several other bad design choices that make it hard to optimise. from the top of my head: automatic closures for OOP methods, overloaded '+' operator, weird 'this' variable, not-quite-lexical-scoping, etc...
Javier
Yes, I'm willing to concede many of your points. It's still better than many of the industry standard languages. Java? PHP? C++? any of the .NET languages? I'll take JS over them any given sunday. (C# is nice tho :P)
Internet Friend
@Internet Friend: C# is vastly superior to JavaScript. They are used for two different things, so they are tough to compare. I try to imagine if IE, Safari and Firefox allowed me to program in C# instead of JavaScript. That always convinces me how much nicer C# is.
Jason Jackson
"They are used for two different things", that's exactly it! It's very possible to run Jscript code within C# (and more, that's the point of CIL, you can do even Visual Basic if you really want). And it's possible to run Javascript within the Hotspot VM. Jobs and tools, jobs and tools.
Internet Friend
+2  A: 

I don't understand why you're trying to compare a scripting language with a browser plug-in. They don't do the same thing. The former interacts with the DOM while the latter runs multimedia apps inside the browser.

Comparing Flash and Silverlight from a performance point of view would seem more useful to me.

EDIT: After some research I found out that you can interact with the DOM in Silverlight. I don't think it can be seen as a good Javascript replacement though, performance concerns aside, unless you have some heavy client-side interaction needed. I see two main disavantadges :

1) You will force your users to download a Silverlight app instead of relying on a relatively small .js file.

2) Your users are required to install Silverlight before using your page.

Franck
A: 

Sre, if you're using "Internet Exploder" it probably will...

If you're using V8 (Chrome) or the upcoming Safari and FireFox, I seriously doubt it ;)

I would love to see that Chess thn BTW where IE is playing using Silverlight and Chrome is using Javascript. THAT would rock MSFT...!! ;)

Thomas Hansen
I use Chrome, but I don't think it is a particularly useful choice for comparison since the market share is so small.
TM
A: 

I'd say yes, since it has .NET's CLR. At that, with resent developments in JavaScript implemented in Google Chrome and in the yet to be fully released Firefox 3.1, one may want do do some benchmarking of their own; I don't know of any comparisons as yet. (anyone?)

Nonetheless, in my opinion, .NET should be generally faster than Javascript, and as has been noted before, this will not speed up the network. Consequently for complex algorithms, SilverLight will be faster, but for network requests, you may not have any noticeable difference.

On the performance question, you may want to have a look at Flash 10 which can allow c/c++ code using "Alchemy". This may be a more portable solution than SilverLight.

partoa
+2  A: 

I'd say that architecturally, it's a wash.

On the one hand Silverlight is MSIL code, which is reasonably fast compared to raw, optimized native code but still runs slower due to the VM (CLR) overhead and will still have slow initial load times when being ngen'd.

On the other hand the speed of Javascript is much less reliable due to the huge variations in Javascript engines which have an order of magnitude, or more, range in performance. You have slow interpreters like IE, though IE8 is speeding things up, and then you have faster compilers/interpreters like SpiderMonkey and V8 which have only recently begun to explore the performance limits of Javascript. There's also new technologies in the R&D phase like TraceMonkey which have tremendous potential to vastly improve Javascript performance (getting close to native code speeds). Javascript does have the inherent disadvantage that it is single-threaded, but given the difficulty of writing good threaded code it's hard to say how much difference that makes.

At the end of the day when comparing apples to apples the real performance bottleneck is the DOM, and there it doesn't much matter what technology you're using to manipulate it.

Wedge
+15  A: 

Speculating is fun. Or we could actually try a test or two...

That Silverlight vs. Javascript chess sample has been updated for Silverlight 2. When I run it, C# averages 420,000 nodes per second vs. Javascript at 23,000 nodes per second. I'm running the dev branch of Google Chrome (v. 0.4.154.25). That's still almost an 18x speed advantage for Silverlight.

Primes calculation shows a 3x advantage for Silverlight: calculating 1,000,000 primes in Javascript takes 3.7 seconds, in Silverlight takes 1.2 seconds.

So I think that for calculation, there's still a pretty strong advantage for Silverlight, and my gut feel is that it's likely to stay that way. Both sides will continue to optimize, but there are some limits to what you can optimize in a dynamic language.

Silverlight doesn't (yet) have an advantage when it comes to animation. For instance, the Bubblemark test shows Javascript running at 170 fps, and Silverlight running at 100 fps. I think we can expect to see that change when Silverlight 3 comes out, since it will include GPU support.

Jon Galloway
Yaaaaaiii for Silverlight!!
Andrei Rinea
The latest Bubblemark numbers for Silverlight 3.0 (with bitmap caching enabled) show Silverlight beating Flash pretty handily and JavaScript by a reasonable margin.
Ken Smith
+2  A: 
TJB
A: 

It looks like that Chrome's javascript implementation is faster than Silverlight

Alok