r/cpp • u/TheRavagerSw • Jun 18 '26
What is the point of Emscripten?
Lately I was writing a manual for building my development environment incase I need to build it again.
I look at the platforms I want to target, and see Emscripten, for wasm32 and wasm64. Lately, I saw an article, saying that all major browsers have supported wasm64 besides safari, and I don't care about Mac users so I thought why don't I just target wasm64, I don't really want to think about going over 4GB anyway.
The problem is, I really want to get to multi language language projects, and rust doesn't have an Emscripten backend for 64 bits. It has one for 32 bits only.
That got me thinking, why am I even doing this, why should anyone run compute intensive stuff from a browser rather than just downloading a binary. I really feel like it doesn't really solve real problems.
Most stuff that people ported to web via emscripten is disgustingly slow, and they have zero toolchain control unlike native development. I can't just build a standard library of my choice from source and use it. Neither can I just use another allocator. It is all a giant black box.
I mean, android development is also annoying, but libraries like SDL just give you the wrappers normally, and the way you build stuff makes sense, you build C/C++ parts normally and just run another build on top of that with gradle and friends.
15
u/thisismyfavoritename Jun 18 '26
it won't necessarily be "compute intensive" but just having the option to not re-implement existing code in JS is actually quite nice. Less maintenance
8
u/erreur Jun 18 '26
I have a project I have been working on for some time where I was able to leverage the same crypto library written in C in both the C++ server and the browser in order to implement end to end encryption. Emscripten made this almost trivial where without it I might have questioned whether or not such a feature was worth the effort.
15
u/Thriceinabluemoon Jun 18 '26
You must be old; people don't install anything nowadays. It needs to be on the web or it does not exist. They'll make an exception for games and manually install Steam, but that's about it. As for why one would want to bring C++ to the web, performance is one, but a less commonly admitted one is obfuscation: Javascript is far too easy to steal or hack, after all.
5
u/johannes1234 Jun 18 '26
Downloading a binary means I have to trust you to run arbitrary code with probably full access to my machine.
Also providing the binary is just the first part: users also have to understand how to run it (do they even have permissions on their work computer to run their own software) and you also have to update it somehow in a secure way (upgrade routines are a fun exploit vector) and when providing some remote apis, you have to deal with the situation where somebody comes with a very old client.
4
u/Alpha2698 Jun 18 '26
"why should anyone run compute intensive stuff from a browser" - Oh dear, no....
People do not just use WASM for browsers. Most of the time, it is used to sandbox critical and vulnerable components so memory violations and untrusted code are isolated.
That being said, WASM is still relatively new, SIMD support for it is spotty (which a lot of third-party libraries utilizes) and compiling things in it requires a lot of experiment because albeit it advertises near native speed, you may not achieve that.
Why? Most libraries are not optimized for WASM. For instance, an image processing software may utilize vectorization and parallel processing to speed up its work. But if compiled to WASM, that process could become extremely slow since it now serializes the same process.
So, using WASM with a third party library that does not officially support is a bet. And if the licensing allows, you'll have to make deep changes to the library.
5
u/Xavier_OM Jun 18 '26
Emscripten is quite fast, and you can build lib of your choice with it.
3
u/FlyingRhenquest Jun 19 '26
Not having to deploy is pretty nice. That's kinda why we have Javascript too. Sure you could build a binary to do all that stuff and maintain it on multiple platforms, or you could just target a popular browser and not do that. It's also not particularly difficult to do REST calls and serialization with emscripten, so if you want to do your front and back end in the same language you don't need to keep another language in your head. Or have to hire another programmer to do Javascript.
1
u/germandiago Jun 25 '26
Porting your native code to the web.
0
u/[deleted] Jun 18 '26
[deleted] — view deleted comment