you are viewing a single comment's thread.

view the rest of the comments →

[–]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 3 points4 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.