|
|
|
|
|
by ootachi
5260 days ago
|
|
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. |
|
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