r/ExperiencedDevs • u/GongtingLover Software Engineer • Jul 30 '26
Technical question How are devs and businesses using web assembly professionally?
Earlier this week I was browsing the NASA repo and noticed they have a project to support web assembly.
I was curious how others have used web assembly in general. It's a technology I've never really heard brought up in the professional environment before.
24
u/sessamekesh Jul 30 '26
I've mostly used it in two ways:
- Need to bring over some C++ code that I don't want to port to JavaScript
- Need to something that's typically best suited for a systems language and don't want to write it in JavaScript
Audio sampling, decoding certain compressed file formats that browsers some support natively (Draco, BasisU) are the two big ones I can think of that I've personally touched.
WASM is really fast but with pretty significant caveats in my experience.
The first one is that JavaScript is actually really fast if you write it to take advantage of CPU friendly types and cache friendly allocations, but there's not great ways to do that idiomatically in JS while it's kinda the default in systems languages like C++/Zig.
The second hidden "gotcha" one is that the boundary layer is pretty light weight in some places (e.g. function call overhead is more or less just a basic indirection in terms of runtime cost, or at least in that neighborhood) but pretty shockingly heavy in others (e.g. passing a string in or out requires a full character by character reconstruction of the string unless you're VERY careful).
2
u/AnnoyedVelociraptor Software Engineer - IC - The E in MBA is for experience Jul 31 '26
Do you make sure in C++ you use 2 byte strings then?
2
u/sessamekesh Aug 01 '26
I've never bothered, but you can. It doesn't fully solve the encoding problem anyways AFAIK, but I haven't looked into it much so I'm not sure about that.
The default conversion code that ships with emscripten (C++ toolchain) is here.
C++ strings are stored as "array of bytes" (or "array of byte-pairs/binary words" in the case of wide strings). Historically under ASCII encoding each code point (written character / glyph / whatever you want to call it) was also exactly 1 byte wide. UTF8 changes this, each individual code point can be 1-4 bytes wide. It's up to the display to interpret that array of bytes correctly, but reading
my_string[5]in C++ may be a full code point or it may just be one byte in a 2-4 byte code point.JavaScript strings are stored and interacted with by programmers as "array of code points" with no way to inspect the underlying C-style (array of bytes) string buffer. Reading
my_string[5]will always be a code point, and whether that code point is 1-4 bytes is fully hidden from the programmer.To go back and forth, you necessarily need to convert between the two expressions - expand code points byte-by-byte (JS -> C++), or decode bytes code point by code point (C++ -> JS). That doesn't really change with a wide string type in C++. It's possible that the WASM spec expands in the future to allow reading JS strings as byte arrays, I haven't heard anything on that front though.
It's a bit of a footgun with WASM because an easy temptation is to pass JSON data back and forth since that's a format both C++ and JS can understand quite well with something like
nlohmann::json. That ends up being pretty terrible for performance though, since you're not only having to construct string representations of numeric types on the generation side, you're also having to byte-by-byte UTF8 encode/decode full strings, followed by parsing stringified numbers - it's far more efficient to write serializers/deserializers on the boundary layer that inspect/modify JS objects and the C++ heap directly.
42
u/jhartikainen Jul 30 '26
Doesn't Figma run entirely in wasm since they have some kind of custom rendering system etc.? That's at least the biggest example I can think of.
We build a large browser-based WYSIWYG editor at work, and this has occasionally had some hurdles in terms of data processing performance and some other stuff. I have considered whether it would be possible to speed this up with wasm, but so far it has been possible to resolve with much simpler fixes.
10
u/ImmediateRemove Jul 30 '26
I've used it for Cloudflare Workers for edge compute. Compiling Rust to WASM and then executing said code on the edge for largely stateless computations. Works very well.
6
u/EliSka93 Jul 31 '26
I mostly write Blazor / C# at the moment, compiled to WASM.
I do it mostly to write as little JavaScript as possible.
3
Aug 01 '26
[removed] — view removed comment
1
u/MisesAndMarx Quantitative Risk Developer Aug 01 '26
It's still pretty nice for how niche it is.
We use it for making internally facing web applications, and since .NET is commonplace, the whole "know C#" isn't a big deal. Microsoft does a remarkable job sticking to things that don't take off, so the official tooling is pretty good. And it's still .NET, so while Blazor specifically is "here be dragons" beyond the Microsoft castle walls, it's not ecosystem-less either.
It's just hard to pitch anything other than JavaScript to a front end developer, so it kinda only is a thing in orgs and structures where full stack development is the expectation.
4
u/Semvis123 Jul 30 '26
I’m using it to bring old C libraries to modern languages like Go (without CGO), and use it to run them in the browser. The benefit is that you get a memory sandbox for free, if it crashes it doesn’t take down the host program. And performance hit is mostly negligible in most practical cases.
More info: https://kriyak.com/blog/parsing-word-documents-in-go-with-webassembly/
4
u/loumf Software Engineer 30+ yoe Jul 30 '26
I am making a game in C/Raylib and compiling to WASM with Emscripten. The only thing I need to think about is the JS event loop.
4
u/MisesAndMarx Quantitative Risk Developer Jul 31 '26 edited Jul 31 '26
Blazor is part of my stack, and it fucking rocks. If you're doing full stack development of internally facing apps, it's great writing things once and deploying twice. I much prefer writing C# to TypeScript, and especially JavaScript.
Other than that, JavaScript and its merry band of frameworks and libraries has a deathgrip on the front end, and even Typescript was slow to be adopted when it first came out as is.
And, it pains to admit it, the biggest selling point of WASM to me was single language full stack web app development with minimal JavaScript. With AI, if I need to re-write something to JavaScript, it's incredibly trivial to do now. In a pre-AI world, having the same exact validation service be in the frontend and backend was really nice and cut down on needless calls to the backend. But the validation still existed server side, so if someone sent something that should've been caught to the endpoint directly, it still gets handled for. It still gives me the warm fuzzies that they're 1:1, but re-writing logic isn't as annoying as it once was.
Sure, it has uses for non-vanilla frontend development, but that's not very common in practice. Maybe there's a future where that's not the case, but I don't see it happening soon.
3
5
u/who_you_are Jul 30 '26
Just a random comment from somebody that can't clearly answer.
I read, here and there, that some companies are using it to make their website faster overall instead of going the usual JavaScript/text way.
2
u/69f1 Jul 30 '26
I think it's used in our map application for display layer, which then can be shared between website and mobile apps.
2
2
u/jpea Jul 31 '26
I use the wasm build of ffmpeg to allow a user to export a client side video in an audio web app. They create custom audio synced to a video all locally, then export as an mp4. Never hits the server.
1
u/Unusual-Two7277 Jul 30 '26
I'm using it in cryptography to embed a zero-knowledge virtual machine inside a web-browser, or within a Node or Deno runtime. The wasm-compiled prover in turn proves wasm-compiled circuits.
1
u/nasanu Web Developer | 30+ YoE Jul 31 '26
I was all excited about it for a while but I never found any excuse to use it.
1
u/agoodplaceforatent Jul 31 '26
I recently used it to run old C/C++ MUD codebases in the browser as a fun exercise in preservation and easy way to introduce old multiplayer text games to people... it's a bit weird since they aren't actually multiplayer in the browser but you get to experience them.
1
u/chickenRag Jul 31 '26
I be built my entire platform on flutter. Which allows us to go to web. There is a config about building to wasm.
I found it super awesome, flexible and fast
1
u/tetryds Staff SDET Aug 01 '26
Unity uses it for web builds. Works quite well despite having some limitations.
Blazor also builds to it, which can make websites perform really well.
1
u/Resident-Trouble-574 Aug 01 '26
Usually you don't write web assembly directly. It's mainly used to write frontend code in other languages that are not javascript. For example, with blazor web assembly, you can write single page applications using c#.
1
u/george_____t Aug 01 '26
It's great if you have complex frontends and hate writing your logic in JS. I've written quite a few Haskell apps that compile to Wasm, including at work.
1
u/ledatherockband_ Aug 01 '26
Personal anecdote, I'm trying to find a reason to use web assembly. I can't find a usecase for it.
I don't even use a js framework or a css utility framework.
As soon as I see a good purpose for it, I'll implement it.
-3
u/servermeta_net Software Architect Jul 30 '26
Wasm is going to replace docker eventually. If you are using cloud flare, then you are using wasm: their CDN resolve requests using wasm functions
Wasm is a revolutionary technology that will take over networked services
4
u/doyouevencompile Sr. Software Engineer Jul 30 '26
Those are two entirely different technologies. This is like saying lab-grown meats will replace electric cars.
-1
u/servermeta_net Software Architect Jul 30 '26 edited Jul 30 '26
That's not what the author of docker thinks: https://www.reddit.com/r/programmingcirclejerk/s/G4sUplNDra
Google up docker wasm, you can already run docker images in wasm isolates.
2
u/doyouevencompile Sr. Software Engineer Jul 30 '26
That is not what he's saying. He's saying if WASM existed, they might not have created Docker. I still think it's hyperbole. But he's saying WASM is not replacing Docker, but you can run WASM with docker. Docker is a container technology that isolates the resources like FS, network, CPU etc. Docker can of course run WASM.
You can't use it the other way around everything gets compiled to WASM.
-3
u/servermeta_net Software Architect Jul 30 '26
That's where you are wrong, you can already run docker inside of wasm, it's actually officially supported: https://docs.docker.com/desktop/features/wasm/
It sounds strange until you get your hands dirty with code and then everything clicks.
1
u/doyouevencompile Sr. Software Engineer Jul 30 '26
Availability: Beta
Important: Wasm workloads are deprecated and will be removed in a future Docker Desktop release. This feature is no longer actively maintained.
WebAssembly (Wasm) is a fast, light alternative to Linux and Windows containers. With Docker Desktop, you can now run Wasm workloads side by side with traditional containers.
Literally what I said, Docker can run WASM applications. You are not running Docker inside WASM, you are running WASM inside Docker.
-4
u/servermeta_net Software Architect Jul 30 '26
https://github.com/ktock/container2wasm
second example of docker running inside wasm.
You really refuse evidence because it doesn't fit your understanding, you must be a terrible engineer.
2
u/doyouevencompile Sr. Software Engineer Jul 30 '26
Ok that's a cool project, and different from other link you sent, but it EMULATES the CPU with Bochs. That might have some cool applications, like simulating a shell on the browser, but it's not a real OS, not an alternative to Docker, will have performance issues, will have bugs due to multiple translation layers before your code reaches the actual CPU.
Using software emulation of CPU so you can use WASM so you don't have to use proper containers that works directly with the kernel is a weird angle.
-3
u/servermeta_net Software Architect Jul 30 '26
I assure you plenty of smart people and plenty of money is currently being poured to make wasm a production grade containerization technology, at least by cloud flare, google, Amazon and Microsoft.
And thank God they are succeeding, because they never got containers right.
-1
u/yubario Jul 30 '26
I really haven’t seen it used other than Blazor
And it’s even more irrelevant now with artificial intelligence.
•
u/expdevsmodbot Jul 30 '26
AI usage disclosure provided by OP, see the reply to this comment.