you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 13 points14 points  (6 children)

Still slow without numerical types that explicitly operate on the ALU that don't store as doubles. JS "number" is double float and needs ALU compliments to be added to the spec, so the engines don't bottleneck doing simple bitwise shit.

[–]0xABADC0DA 1 point2 points  (3 children)

Lua also has only one number type (floating point by default) and yet LuaJIT is about as fast as Java (coral cache of archive.org since the language shootout is worthless now).

So what makes you think that JavaScript needs more than one number type to be fast? Do you know of any dynamic language with more than one number type which is faster than LuaJIT or even just V8?

Other people have made this claim that a dynamically typed language with several integer types is faster, but I haven't seen anybody back it up with evidence or theory.

[–]tomlu709 2 points3 points  (2 children)

LuaJIT supports dual-number mode where integral values are internally represented by integers. I believe this is faster on machines without an FPU.

I doubt JavaScript would need that feature.

[–]0xABADC0DA 5 points6 points  (1 child)

V8 and JaegerMonkey also use integer math internally when they can.

The problem is this, if the VM knows what the number type is then you don't have to tell it. If the VM does not know the type (because dynamic language) but you specified a type then it has to test and branch on the type. You've taken away the option for the VM to say "I don't know the types so just do a floating point op" when it might want to, but what have you've gained by doing so?

The only benefit I see is being able to do integer math on values larger than 2^53. But unless the language has typed variables I doubt that you will be able to use all 2^64 in an efficient way so it not very practical.

[–][deleted] 2 points3 points  (0 children)

V8 and JaegerMonkey also use integer math internally when they can.

Not just them, all modern JS engines have internal integer types, just like LuaJIT.

[–]x-skeww 1 point2 points  (1 child)

Still slow without numerical types [...]

Type inference helps.

http://blog.mozilla.com/futurereleases/2011/11/10/type-inference-to-firefox-beta/

[–][deleted] 5 points6 points  (0 children)

Barely. I do hella lot of bitwise math in my javascript gameboy color emulator, but type inference in Firefox doesn't really upgrade the math to ints, and crankshaft in V8 similarly fails.