The V8 Myth: Why JavaScript is not a Worthy Competitor
blogs.adobe.com
blogs.adobe.com
As far as actual points in the fine article -- a test using some sort of strongly typed data on an unreleased actionscript vm ran three times faster than v8 running similar code.
I'm not shocked at all, and think Javascript could badly use at the least some type hinting, personally. But, this author is at best just missing it, at worst is misleading others.
I recently ported a Flex app to HTML5. Frame rates quintupled on a modern browser; in a real, mixed-use environment, ActionScript-based tools, interpreted with the Flash or Flex runtime, are roughly one-fifth the speed in the modern browser.
If this speed delta trended the other way, Flash would still be vigorously defended by developers all over the world who would say "we have to have this speed, don't take it away from us!"
In the V8 environment it should be possible to aggressively optimize the code in question with various command line options. Where is -O5?
The real problem is a lack of an open-standard for JavaScript bytecode. Being able to serve "pre-compiled" JavaScript would go a long way towards improving performance.
function f(x) {
x = x|0;
...
}
This has the effect of forcing an int interpretation for the argument, and there will be no type checks or unboxing performed thereafter.Because a variable can always change types, it's actually trivially proven that in a dynamically-typed language, there will always be programs in which the type cannot be inferred.
I'm not sure what your point with this post was because if you litter your C/C++ code with non-static casts, it is also going to be much slower than code without casts.
I understand that actually getting speed out of JS for binary data is still quite 'hacky' though, for instance Fabrice Bellard used Typed Arrays extensively implementing his Linux-on-Javascript project: http://bellard.org/jslinux/tech.html
Optimizing code written in a dynamically typed language is a pretty well understood problem (now) thanks to the SELF research at SUN and more recently the V8 Javascript engine. Both VMs employ type profiling at runtime to figure out what the compiler should assume the type of a dynamically typed variable should be. It can then emit code that treats a variable like it always has the profiled type - like a C++ compiler would. When such an assumption is broken at runtime, implementations typically fallback to an unoptimized version of the code (V8) to execute the rest of the continuation. Well written code is expected to achieve type stability pretty fast making the fallback overhead insignificant.
We staged out of that architecture by implementing a REST endpoint on top of Zend, and moved our graphing over to the (now-superceded) protovis library.
Our engineers weren't used to worrying about data transfer, so we had to do a little bit of engineering work on the JSON side once we switched out, but the graphs, charts and rendering are VASTLY faster.
That said, it could well be the Flex runtime that added all the badness; flash games definitely render faster than our app did.
Adobe: Oh, had enough, eh?
The Web: Look, you stupid bastard. You've got no arms left.
Adobe: Yes, I have.
The Web: Look!
Adobe: Just a flesh wound.
The Web: What are you going to do, bleed on me?
Adobe: Oh. Oh, I see. Running away, eh? You yellow bastards! Come back here and take what's coming to you. I'll bite your legs off!
At least it's not Dart!
I don't want to dodge your question thought, the answer is yes I have worked on some JavaScript code bases that are several MLoc. Which I would consider for conjecture sake to rank in the largest. what constitutes that bar is up for debate whether they are the top 50 or 500th or 5000th largest, but I do feel that they qualify as large code bases. Which sufficed for the point I was making.
If you can't tell us that, at least tell us what _kind_ of project it was please.
Although I probably won't. Because I don't have to.
Because unlike with a traditional code base, much of the functionality is provided by the browser (CSS, HTML, SVG, Canvas, Image Support, Geolocation, Storage, you get my point) and not by external libraries which add to the lines of code.
Static typing evangelists seem to have a blind spot: they persistently tend to assert that you can't write good and large dynamic codebases.
IIRC in webOS a substantial portion of the user-land utilizes JavaScript, as a whole one could surmise that they constitute modular parts of an overall system. I do not know what the TLoc on webOS is, but I would assume that it would have to be in the ball park of large. I think it is as valid as the total line count of windows or android it is also the problem with looking at these things from just a TLoc perspective.
Static typing evangelists seem to have a blind spot: they persistently tend to assert that you can't write good and large dynamic codebases.
Thanks you probably summed up my post better than I did.
I have a PHP Project that is about ~200Kloc , ok that's not enormous (and it's about 60% boilerplate) and I can maintain it happily enough but I wouldn't want to let a large team loose on that.
Use Native Client. You'll get as close to machine code as you'll ever get, while running in a sandbox. The only way to go faster is to fully trust the code on your machine.
Checkmate.
See, I can write the word checkmate, too. How many more times can we come up with a slightly better argument, using only one train of thought about what is actually a very complicated issue involving multiple vendors, multiple platforms, multiple standards committees, ease of use, ease of deployment, different memory, bandwidth, and cpu constraints, and then just say 'checkmate' as though everyone else is being completely ridiculous?
Several, I bet.
Nitpick: The only way to go faster is to use the hardware privilege separation that Chrome is always already running under, which is considered insufficient to sandbox untrusted code for historical reasons and organizational reasons (Chrome doesn't have much control over the kernels it's running under), but no technical reasons.
Also, I think the question is how to get performance for dynamic runtimes. Native client isn't inherently dynamic. I guess you could compile Lua into native client and build your app ontop of Lua but then you still have the issue of how to get a performant dynamic runtime.
Compared to:
$ vim helo.html
<script>
alert("hellooooo");
</script>
And if you can't write that from scratch, ViewSource on most web pages will give you a good clue.That looks like trump for mindshare, disputed performance questions aside.
Oh, and that was after I had to add manifest types everywhere like I was writing Java, without a free IDE to complete that junk for me. All the docs I found assumed you have the Flex IDE or Flash Builder whatever it is. Which costs over $500. Apparently it's still 1995 at Adobe Inc.
And people say Haskell is hard to use. I had no trouble getting started with Haskell. `ghci<return>` and away you go.
(I'd like to think that it wasn't my fault. Maybe I'm not as capable as I think I am, but I have written compilers and interpreters in C, Haskell, and Lisp. I have written an x86 assembler in Ruby that emits real x86 machine code as Mach-O binaries. I can write hello world in at least 10 languages. I feel like I have the capacity to understand this stuff. Hello world with an existing compiler should be a piece of cake, not an exercise in frustration.)
edit: Ok, I searched for "flex hello world" and did find something that looks like what I want. I deleted Flex and can't try to run it now though. Still don't like all the complexity but it does look like what I said I couldn't find: http://livedocs.adobe.com/flex/3/html/help.html?content=02_G...
I did read O'Reilly's Flex book first though. I'm not sure people code Flex for fun, so good documentation costs money.
Was this your first time writing code for a GUI toolkit? Flex has an interesting model that merges XML definition of a UI with module-based code. I don't find it particular complex compared to say, writing an MFC application or C Win32 code to write a UI. I actually prefer it to the jungle of HTML, CSS, JS and dozens of JS libraries which aren't really geared for a professional type UI and fall down when you want to display 10,000 items in your table.
You do not need to purchase anything from Adobe to compile a AS3 project.
edit: I don't mean for this post to be as negative sounding as it may appear, it's not a comment on your abilities.
Download that and the free Flex SDK from Adobe, create a new Flex 4 project and stick this in the Application tag in the generated Main.mxml file and you are done:
<s:Label text="Hello, world!" />
Use an AIR Flex 4 project instead with the same label control and now your app runs on both Macs and PCs (and Linux but not as cleanly) in its own native window with full access to the native file system and the Internet without any AJAX proxy issues.I admit its not as nice as instant browser compilation but for some class of applications Flash/Flex is very nice.
For those of you who haven't done any AS3 programming it is a superset of the ECMAScript 4 standard while browser based Javascript uses ECMAScript 3.1. AS3 "feels" more like Java in that it adds syntax for types and classical inheritance but if you are lazy you can use * for the type and prototypical inheritance still works. Both of those might horrify static language/GOF purists but it does allow you to pass objects around on the side without refactoring pure OOP interfaces or inheritance trees.
In the end I enjoy working in AS3 with its static type checking more than I do Javascript pushed through JSLint. With large Javascript apps, even with strict use of the Module pattern, I feel like my code contains hidden runtime bombs waiting to do off.
Some caveats - I'm on a Windows machine and Flash runs great for me. I've also never developed with "use strict" in Javascript, which I probably should.
The argument assumes that compiling a program is a fixed amount of work, hence a AOT compiler will always have an advantage.
This is wrong.
We can chose how much effort a compiler expends, and this choice has a complex relationship with the execution speed of our built program. Read Andreas Gal’s PhD thesis, then look through the source of LuaJIT for an example of how one can achieve peak execution speed while spending only a fraction of the time that’s typical inside the compilation machinery.
What this means is that AOT vs JIT vs Tracing is a complex topic with no simple winner. Real systems will increasingly be hybrids.
Lastly, wtf does Santa have to do with anything? If you’re making a claim, support it with a logical argument and evidence, not a lame rhetorical appeal.
Maybe this illustrates the dichotemy between traditional engineering and computer science, but in most other forms of engineering you want just-good-enough-to-fulfill-the-requirements because any better means you are spending extra money or doing extra work uneccessarily.
If javascript lets you write a game that runs at a solid 30 frames per second, and write it easily and portably for free, any additional performance is overkill.
For many of the simple types of games people play in a web browser, javascript has been good enough for years. Increased hardware performance will only help javascript.
Dusting off the age-old interpreted vs. precompiled fight as a closing argument strikes me as a little weak as well. If raw runtime performance and the benefits of static typing were the ultimate measure of a language's utility, nobody would write Ruby.
The author would probably be wise to read up on disruptive innovation. The biggest mistake an incumbent can make is to overestimate the importance of the disruptor's weaknesses while the disruptor is busy eating the incumbent's lunch.
The article, however, comes across as clueless and obnoxious.
For example, using the code from http://iq12.com/blog/as3-benchmark/ which I've put up here: http://people.mozilla.com/~jmuizelaar/v8-flash.html, I get a score of 2134 with Flash vs 11796 in Chrome. At least on this benchmark, it looks like V8 is a worthy competitor.
I understand that JavaScript has its limitations, and Google tried to address this with their own language Dart. But this boils down to, you have a 100 billion dollar company serving 1 billion searches a day so you have different scalability issues than I do. But that’s not my problem. With the current technologies like Node, MongoDB, Reids, etc… I can build a 1 billion dollar startup without the same scalability issues that a 100 billion dollar company has.
I would be quite happy to have a these scalability issues once I have a 100 billion dollar company then it will be my problem. But until then, getting a start-up up and running is ridiculously hard, the last thing I need is companies generating truckloads of cash putting their development issues on to open source developers.
I realize that one person does not the voice of Adobe make, but I would have thought that he would realize that Javascript is very often not used in isolation, and more often than not as part of a large suite of technologies (Databases, network infrastructure, backend code - if not JS).
Personally I deal a lot with Video on the web, and although I have a Flash player my main body of development is in native implementations and transcoding profiles for Ogg, WebM and using x264 for preview.
So this is actually about the language beyond Flash.
"The project to integrate Tamarin and SpiderMonkey was called "ActionMonkey",[6] but was canceled in 2008[7] because Tamarin's interpreter turned out to be slower than SpiderMonkey."
Ironically, it was too slow :P
I realize current JIT sucks in many ways, but seriously... claiming that "we can put this compiler in front of our stuff and since the other guys can never, never figure out how to compile first, we will win forever" isn't just stupid. It seems willfully stupid.
Like, what about the second and successive times you run a given page's JavaScript, like if the page were in cache. Are they certain that open source's brain trust can never figure out how to compile that ahead of time?
Really?
However, one could make the same argument for C++: Why Python is not a worthy competitor. Sounds silly? It is, just like the original post.
Not quite. Nobody claims that python will completely eliminate the need for C++, but there are people claiming that JS will replace flash.
But yes, it seems absurd to say that JIT compilers will never get better, especially given the improvements we've seen in the last few years.
1) I don't know a single person that would seriously argue that dynamically typed languages can perform better than their statically typed cousins.
2) As we all know, programming is the art of making tradeoff. One common pair is ease of writing vs. performance...
3) I think Adobe should be more worried about making a flash player/plugin I can't use to warm my hands by playing video after I come back from lunch.
Most of the time your app will probably be slow because of the DOM interactions, not because of your JavaScript, most time is usually spent in the rendering and fetching stuff from the network.
To give a better viewpoint: You won't write a database engine in Ruby or PHP, you will write it in C, C++, Java, but you will use PHP/Ruby to interact with it.
We have low level programming and high level programming for these distinct purposes. I am sure that if you won't write something in JavaScript you will probably not write it in ActionScript either.
There are many horses in the Javascript optimisation race. Chrome is the faraway leader, but all major browsers have delivered large improvements in Javascript performance over the past few years. Actionscript has hardly improved in five years.
That's a big if.
But in all seriousness, who couldn't have guessed that there would be some Flash/Actionscript dead-enders? Incredibly unsurprising that this was posted on adobe dot com.
And I hate it. It is broken as a language (var hoisting, this can mean pretty much whatever you want it to, no types, not even a good damm s32int).
But it works on all platforms and so it will always beat Flash.
However, what's wrong with not having types? Sounds like you're just not a fan of dynamic languages since this isn't a JS-specific issue.
http://disnetdev.com/contracts.coffee/
Compiles to beautiful JavaScript and gives programmers the ability to check types at compile-type. If you've never used it, I'd compare CoffeeScript to an amalgam of Ruby and Python, with a little Haskell thrown in (take a look at how you specify contracts, for example). If you like functional programming, you'll love CoffeeScript:
['fizz' unless i%3] + ['buzz' unless i%5] or i for i in [1..100]
(fizzbuzz one-liner from http://ricardo.cc/2011/06/02/10-CoffeeScript-One-Liners-to-I...)July 2010 – Present (1 year 7 months) specification, design, and implementation of ActionScript
Well, that explains a lot now, doesn't it?