133 points · by fctorial · 5y ago · 94 comments
You can find the link to the source of any article at the bottom of the page.
Beware the lure of MDX/equivalents. If you want to provide structure to your content and maintain it colocated to where you use it (or imported and type checked for where you have that kind of reusability), components in Markdown is an awful experience. Inverting that and writing Markdown within posts is my current solution. It’s not as nice as a plain .md file but it lets me mix writing and structure without compromise
I made a couple of short explainer videos on it:
- design goals and instruction set:https://youtu.be/VOaSaShAYb0
- mechanizing safety proofs for wasm: https://youtu.be/zsPVbmEPTlA
“...provides access to several operating-system-like features, including files and filesystems, Berkeley sockets, clocks, and random numbers, that we'll be proposing for standardization.
It's designed to be independent of browsers, so it doesn't depend on Web APIs or JS, and isn't limited by the need to be compatible with JS.”
"Usenix Security '20-Everything Old Is New Again: Binary Security of WebAssembly"
> Notably, they don't appear to even try to break the WA-host memory barrier, which I actually find to be a validation of the core design goal of WebAssembly: isolate the damage a vulnerable program can inflict to the memory space (and thus also output) of that program. Protect the host from the program, but not the program from itself. Also, maybe don't dump WA output you can't validate directly into DOM.
> Protect the host from the program, but not the program from itself.
All nice and dandy, except that the goal of WebAssembly is to extend the host, and have the host be dependant on the program behaviour.
A host unaware that the program is compromised can be led to take decisions that it wouldn't otherwise do, like allow a basic user to acquire admin credentials, that were supposedly correctly validated by the program.
I am really eager to see the amount of CVE's on WebAssembly to start poping up, then the whole WebAssembly advocates can tell the world why we had to ditch PNaCL and CrossBridge, 10 years of regress, and get the same outcome in the end.
On another side, compiling existing C/C++ libraries to wasm is still very painful. I struggled a lot using Emscripten to port FFmpeg to wasm - you have to compile EVERY dependency to wasm (so I ended up re-compiling libopus, libmp3lame, etc.) and the compiler warnings are often super cryptic which made the entire process a complete nightmare. The process really needs a lot of work still.
For anyone that's interested, this is the result from my endeavor: https://github.com/aeroheim/audio-file-decoder
And also check out a great general purpose FFmpeg wasm port here: https://github.com/Kagami/ffmpeg.js
This is a scenario where the Bazel model is a good fit IMHO. Bazel rebuilds all of your dependencies from source. This makes it easy to compile all of your dependencies with an extra flag (eg -fsanitize=address for ASAN) or using a different compiler (eg Emscripten).
While it can be annoying to wait for the world to rebuild every time, this is a use case where it shines.
I’ll share mine if you share yours:
https://github.com/sorbet/sorbet/tree/master/tools/toolchain...
When we set this up to compile Sorbet (C++ codebase) for https://sorbet.run, it involved what I considered an inordinate amount of boilerplate and arcana.
To be fair since we set it up it’s hardly ever needed to be touched, and I could probably cargo cult this into future projects where I wanted to use it, but I wouldn’t exactly say that bazel magically makes the pain of emscripten go away.
Curious to hear otherwise.
I was under the impression that Emscripten was just an alternative compiler binary, such that you could just use CC=emcc. Is that not the case?
Why do I need to have a mix? of Python, Java and JS based tools in addition to the C and C++ compilers?
With no option to skip downloading them.
[0]: https://github.com/WebAssembly/design/blob/master/Nondetermi... [1] A blog post on rollback netcode (not in wasm): https://ki.infil.net/w02-netcode.html
Look how much spread there is in the JS, and how little there is in the wasm.
Depending on what you're doing, this may or may not matter to you.
[1] https://stackoverflow.com/a/30919039/225272
[2] https://www.linux.com/training-tutorials/math-v8-broken-how-...
It's a design tool that runs entirely in your browser as a WebAssembly-based frontend tool (coded in C++ IIRC). Go kick the tires and play around with it--you will be amazed how fast, fluid and downright native the experience feels.
IMHO I think we're going to see more and more frontend experiences like this in the near future. For certain classes of complex apps we're starting to see the overhead of all the frontend JS cruft, polyfills, reactivity, etc. are just getting out of hand and destroying browsers on low-spec phones and machines. A little Go/C++/Rust/AssemblyScript, etc. app compiled to WebAssembly interacting with the DOM directly is incredibly fast and space efficient. The build system for something like Go or Rust is so much more sane and easy to use vs. a complex modern JS Webpack setup too.
edit: More details here: https://www.figma.com/blog/webassembly-cut-figmas-load-time-...
- An in-browser crossword puzzle generator: https://crossword.paulbutler.org/ (source: https://github.com/paulgb/crossword-composer)
- A multi-player word game: https://redwords.paulbutler.org/
- A library for synchronizing state between clients, used for that word game: https://aper.dev/ (source: https://github.com/aper-dev/aper very WIP right now)
In my experience, the single biggest perk of using WebAssembly is that I can use a language I'm very productive in (Rust) compared to JavaScript. Everything else is secondary. That said, I think these projects have specific advantages by virtue of being WebAssembly:
- The backtracking search used for the crossword puzzle generator is carefully implemented to reduce memory allocations. This would be tough to do in JavaScript, and I believe it's partly responsible for its performance.
- The word game uses a compression algorithm that benefits very noticeably from wasm-opt, to the point that I can't run it without it. Given that wasm-opt takes a non-trivial amount of time at compile time, I suspect the JavaScript JIT would be slow at doing something similar at runtime. This is just conjecture, I haven't checked.
- What Aper does just wouldn't be possible without Rust features like Serde and macros.
The old code was also very "tight-loop" code that's just math, and no GC allocation, so it's not applicable to many people here yet, and it's possible that JS interpreters have improved since when I ported (GC behavior has gotten quite noticeably better in V8 in the last two years), but I'll take the speedups I can get.
For comparison:
Old TypeScript: https://github.com/magcius/noclip.website/blob/master/src/Co...
New AssemblyScript: https://github.com/magcius/noclip.website/blob/master/src/as...
Wrapper for WebAssembly execution: https://github.com/magcius/noclip.website/blob/master/src/Co...
[1] https://github.com/jeffkaufman/bucket-brigade/blob/master/ht...
In my case, that would be anything written in Python that targets WebAssembly.
If Javascript is obviated, that's one less programming language mouth to feed.
I've tried go, rust, c/cpp, webassembly.
go - big bundle sizes because of gc I am guessing, idk.
c/cpp - I haven't touched c/cpp in a really really long time, but probably the other really good fit.
rust - I see rust as the successor to what I would've used c/cpp for, but not sure if rust ecosystem is still fully there. Last time, I had some weird issues with wasm-bindgen.
AssemblyScript(AS) - Something I really like and what I am most comfortable with now that I've been doing java/c#/ts for so long now. Also it's geared towards wasm which is nice. It's my favorite solution, but I don't really get it like I get the other solutions because everything else is an "actual language" that's used for other things. I am really not sure what the strict ts stuff is about, the devil is in the details, and this is getting way too high level.
c# - Maybe good if someone is heavily invested in .net.
At the end of the day, these wasm blobs are probably for heavy tasks like functions with a lot of loops, not full systems, so any simple solution would probably work. It's why I like AS (or even cpp), but sometimes these tasks require some niche external libraries in which case rust would be probably be the best option.
The runtime will eventually be available as well, it is being ported with help of WASI.
Much better option than emscripten and all the machinery it brings along, with three languages (Python, JS, Java).
window.console.clear = function arsehole() {console.log(arsehole.caller, "Asshole script called console.clear()")}
before it executesStuff state of the art adblockers (uBO) inject to block ads today: https://raw.githubusercontent.com/uBlock-user/uBO-Scriptlets...
WebAssembly
WebAssembly {compile: ƒ, validate: ƒ, instantiate: ƒ, compileStreaming: ƒ, instantiateStreaming: ƒ, …}
delete WebAssembly
Uncaught ReferenceError: WebAssembly is not definedThey've been working on adding that for a while in the standard. But it's a complex topic, which is why it is taking time. You can of course bundle your own garbage collector and statically compile it into wasm. That's why Go, C#, etc. can target WASM.
Jetbrains is actually working on a compiler backend for wasm in their new IR compiler for Kotlin. Apparently they are planning to not bundle their own GC and will try to rely on the WASM gc when that is ready. I'm not sure how close they are to having a usable release. But I expect early betas might start happening late this year or next year.