3 ms·
> I still entirely don't understand the point of web assembly - at best isn't it a pretend emulation layer? No ... it's a "bytecode." A runtime for an interpr
by RiverCrochet 3y ago
> I still entirely don't understand the point of web assembly - at best isn't it a pretend emulation layer?
No ... it's a "bytecode."
A runtime for an interpreted languages like Javascript can operate directly on the code text and execute the source code. The runtime has to parse, lex, and interpret the code text into things that represent what the code should do - in realtime.
"Bytecode" is basically that parse/lex/interpretation step already done. The runtime that interprets bytecode (often called a JIT or jitter) is drastically simpler since it only has to know how to do the relatively simple bytecode operations, instead of complex high-level things like Javascript syntax and object moderling.
Benefits:
- multiple languages can be targeted to that bytecode (Microsoft does this with it's CIL/.NET)
- porting the JIT to different platforms is potentially easier and less error/security-issue prone than the runtime for a high-level langauge
- bytecode is easier to examine for security issues than high-level languages - if you want sandboxed code - a whole lot easier to do in a JIT than a full interpreter.
- if you design your bytecode right, the JIT could basically translate it to actual CPU assembly language fairly easily.