News for hackers. Stuff that matters.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by astrodust on Wednesday January 18, 2012 @10:43AM (#3480217)
This is what I'm having trouble believing. If ActionScript can be "compiled to death", where in this case "compiled" means "to bytecode" then presumably the same thing could happen to JavaScript.

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.

Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by ootachi on Wednesday January 18, 2012 @11:21AM (#3480435)
Nonsense. JavaScript bytecode would still be dynamically typed. At best a JavaScript bytecode standard would be equivalent to a compressed AST. That still might be a useful thing to have, but it wouldn't improve runtime performance.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by vessenes on Wednesday January 18, 2012 @11:08AM (#3480337)
Well, the problem (one problem) is that Javascript has no typing system. This makes running valid javascript code super, super slow at times. You can't promise to a javascript interpreter that you will always and only use the variable i_am_only_ever_an_integer as an 8 bit integer. This makes lots of things super slow.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by ootachi on Wednesday January 18, 2012 @11:19AM (#3480412)
Of course you can promise types to the JS engine. Ints in particular are easy. With modern type-inferring JITs like SpiderMonkey, an expression like "var x = 3;" will infer x to int, and there will be no type checks or unboxing. In more complex cases, you can add "|0". For example:

  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.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by vessenes on Wednesday January 18, 2012 @02:29PM (#3481401)
Interesting. I didn't know this.

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

Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by VMG on Wednesday January 18, 2012 @12:33PM (#3480777)
but you have to admit this isn't very obvious or well documented
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by adgar on Wednesday January 18, 2012 @12:49PM (#3480863)
> Of course you can promise types to the JS engine.

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.

Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by ootachi on Wednesday January 18, 2012 @01:31PM (#3481088)
Well, statically-typed languages have a "dynamic" type too. Consider void * in C and C++ and Object in Java and C#. You have to downcast to do anything with them. That's the equivalent of what JS is doing with its dynamic typing. The basic difference is that the "dynamic" type is the default in JS, and the static type is the default in statically-typed languages.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by georgemcbay on Wednesday January 18, 2012 @01:55PM (#3481223)
The premise of this article is that Javascript's pure dynamic variables lead to slowness.

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.

Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by ootachi on Wednesday January 18, 2012 @02:38PM (#3481441)
The parent comment was pointing out that there exist programs in JavaScript in which the types cannot be inferred. All I was saying was that this is not unique to JavaScript, or to dynamically typed languages generally.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by jasonwatkinspdx on Wednesday January 18, 2012 @01:16PM (#3481007)
Statically.
Re:The V8 Myth: Why JavaScript is not a Worthy Competitor by kaushiks on Wednesday January 18, 2012 @11:08PM (#3483178)
That is not true. I'm not entirely sure what you mean by "no typing system" so I'll go ahead and assume what you likely meant - no static type system.

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.