5 ms·
Maybe a stupid question but why does the browser itself need to do compilation? Why can’t WebAssembly developers compile ahead of time and just serve the binar
by arduinomancer 8y ago
Maybe a stupid question but why does the browser itself need to do compilation?
Why can’t WebAssembly developers compile ahead of time and just serve the binary?
- AndrewDucker 8y agoBecause they don't know what they're compiling to. The browser could be running in a wide variety of hardware.
- arduinomancer 8y agoRight, seems obvious now, thanks
- sp332 8y agoAndrewDucker I think has the main point, but it's also easier trust and sandbox a binary that you've built yourself.
- mactrey 8y agoThis is answered in the article (pretty far down, I'll admit): >But if all we have is the link, there are two problems here that we haven’t addressed. >The first one is… you go visit this site and it delivers some code to you. How does it know what kind of code it should deliver to you? Because if you’re running on a Mac, then you need different machine code than you do on Windows. That’s why you have different versions of programs for different operating systems. >Then should a web site have a different version of the code for every possible device? No. >Instead, the site has one version of the code—the source code. This is what’s delivered to the user. Then it gets translated to machine code on the user’s device.
- rkangel 8y agoTwo reasons: Portability - you would need to know what you're compiling for, in the same way you need to compile a different version of your program for your PC and your phone. You could imagine a system where some pre-compiled versions exist for certain browser/host combinations to make life faster for the majority case thought except: Security - the primitives that WASM has available are limited and only affect stuff in the sandbox. The browser then compiles that to machine code and can know that the machine code will only affect stuff in the sandbox. This is exactly how JS works - unless there's a browser bug, JS can't write to an arbitrary place on your harddisk (for instance). If machine code was provided directly, then the browser couldn't easily verify that the machine code only did safe things (because machine code can do anything, unlike WASM).
- nutjob2 8y agoBecause you don't know the target architecture and configuration.