3 ms·
"It would make much more sense if it were compiled to some kind of bytecode (like NaCl)." asm.js is a bytecode. The ".js" is misleading; it's not wrong, but it
by jerf 13y ago
"It would make much more sense if it were compiled to some kind of bytecode (like NaCl)."
asm.js is a bytecode. The ".js" is misleading; it's not wrong, but it's misleading. asm.js is actually a bytecode specification that has a syntax that overlaps (but is not a superset of) Javascript, and the semantics of the bytecode overlaps (but is not a superset of) Javascript, but it is not Javascript. It's a bytecode that happens to have a serialization to a Javascript-compatible syntax.
Do not be fooled by the surface appearance and the name. Look at what it does. It is a bytecode, just one with a bizarre serialization. (And as a result of that serialization, the most literal interpretation of "bytecode" admittedly doesn't quite work, but it's a bytecode in every way except for a literal fixed-length code of bytes.)
- CmonDev 13y agoHow many CPU cores can said "bytecode" utilize at a time? Does it make a difference between value and reference types for optimal performance?
- kevingadd 13y agoasm.js doesn't have support for reference types. You can access threads via the HTML5 'Web Worker' feature.
- CmonDev 13y agoSo, all the C++ threading code will automatically be converted to 'Web Workers'?
- flohofwoe 13y agoNo, but it's not a great deal to write a parallel execution subsystem in C/C++ which abstracts the differences between pthreads and WebWorkers away. Using low-level pthreads primitives directly in high-level code is a bad idea anyway.
- flohofwoe 13y agoasm.js code is just numbers and functions, no JS "objects". Passing a C++ object by reference resolves to passing a pointer just like in native code (a pointer in emscripten-generated code is actually an index into the typed-array representing the heap). A nice side-effect of this is that asm.js code doesn't trigger the garbage collector.