A
Alon Zakai
kripken.github.io · Personal blog · on HN since 2013
Alon Zakai, creator of Emscripten, writes about compiling C and C++ to JavaScript and WebAssembly.
What HN saysHN links it for WebAssembly performance numbers, such as WasmBoxC sandboxing overhead, and for demos like BananaBread showing 3D games on the web.
81HN people shared it
64linked it in comments
22stories submitted
760story points
4 months agolast shared
2013people per year2026
Most-shared posts
- 1Lua.vm.js9 people · 64 points · first shared 2013 · 16 comments on HN
- 2WasmBoxC: Simple, Fast, and VM-Less Sandboxing7 people · 234 points · first shared 2020 · 106 comments on HN
- 3Emscripten site7 people · first shared 2014
- 4Big web app? Compile it6 people · 92 points · first shared 2013 · 43 comments on HN
- 5Interacting with code6 people · first shared 2016
- 6Pthreads5 people · first shared 2016
- 7BananaBread: Cube2 Port to WebAssembly4 people · 2 points · first shared 2017 · 1 comments on HN
- 8Repl4 people · first shared 2013
- 9Massive3 people · first shared 2014
- 10Demo3 people · first shared 2014
- 11Portability guidelines3 people · first shared 2015
- 12Run LLVM Assembly in the Browser2 people · 95 points · first shared 2014 · 11 comments on HN
- 13Emscripten and WebAssembly talk slides2 people · 19 points · first shared 2015 · 1 comments on HN
- 14Fuzzers and Reducers as Productivity Tools2 people · 5 points · first shared 2019 · discussion on HN
- 15JavaScript + Other Languages2 people · 1 points · first shared 2013 · discussion on HN
What HN people wrote when they linked it
andai · 2024-02-14
It's very laggy on my phone too. (Several seconds input delay.) That's fairly normal for a game made in React though (at least the ones I've tried). Is the paid version also made in React?
For some context, my phone is old (2016) but I do find it amusing that it can run this page with a physics engine and 3D rendering without any lag http://kripken.github.io/box2d.js/demo/webgl/box2d.html
Your game looks great though, and the website matches it perfectly! Nice work
(As an aside, I'd urge you to take the from-scratch ethos just one step further and make you next game without any libraries, or with sensible exceptions like Howler and Pixi.)
azakai · 2021-12-06
There are detailed performance numbers here on a variety of real-world codebases:
https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html
tl;dr Something like ~14% when using the best bounds checking strategy, or ~42% when using the most portable one. (There are options in the middle as well.)
steveklabnik · 2017-11-14
Currently, the best supported languages are C, C++, and Rust. Languages that have runtimes require their runtimes to also be compiled in, and so are much heavier weight.
For C and C++, you have emscripten. For Rust, we have an emscripten-based toolchain that works today, but have a PR open for using LLVM's built-in wasm backend.
For emscripten: https://kripken.github.io/emscripten-site/docs/#
For Rust: https://hackernoon.com/compiling-rust-to-webassembly-guide-411066a69fd… (slightly older but still should work afaik) And the new backend https://github.com/rust-lang/rust/pull/45905
DrBobDengler · 2017-04-20
Anybody had any experience with code translator programs that say they can take a program in one language and translate it into another. This would greatly reduce the time and cost of rewriting my app from .Net to web-based, but sounds too good to be true.
Such as ( I have no relation/interest): "Emscripten is an LLVM-based project that compiles C and C++ into highly-optimizable JavaScript in asm.js format. This lets you run C and C++ on the web at near-native speed, without plugins. http://kripken.github.io/emscripten-site/index.html
Emscripten can be used to compile almost any portable C++/C code to JavaScript. http://kripken.github.io/emscripten-site/docs/porting/guidelines/porta… "
Any thoughts would be helpful. As I said, these sound too good to be true, but worth asking the experts about!
ZenoArrow · 2017-08-26
Most web-based games will probably remain to be in 2D (for multiple reasons, including development cost and accessibility), but 3D games on the web are certainly performant enough.
To give one example, bananabread is a tech demo showing off what can be done with asm.js and WebGL (performance is likely to get even better with WASM):
http://kripken.github.io/misc-js-benchmarks/banana/index.html
As for whether a VM has an overhead compared to native, of course it does, but you're not going to convince anyone of your viewpoint by stating something that's already obvious to us all. The performance of web-based games doesn't have to be the best, it just has to 'good enough'. I personally don't think we'll fast adoption of WebVR, but I'm glad it exists as it helps to have it as a goal to improve 3D performance, almost certainly leading to reducing the performance overhead of browsers (as low latency is a key component of a good VR experience).
moron4hire · 2017-02-27
> First, let’s discard the HTML5 Fullscreen API, it sounds great at first since it provides a fullscreen canvas without any browser window chrome. In reality it is quite useless however, since fullscreen mode must be activated from an input handler, and even then a warning is printed which has a different look and feel on each browser. The kicker is though that the Fullscreen API isn’t supported on iOS Safari (last I checked).
In my own WebGL applications, I support the HTML Fullscreen API, with a shim on iOS that cheats the data that indicates the call succeeded. Since the majority of people are not-iOS (i.e. desktop-of-any-OS or Android), there's no reason for them to receive a shitty experience just because Apple can't be arsed to implement web standards.
> Emscripten’s soft fullscreen ... only has one downside: when activated, it hides all other HTML elements on the page, so it can’t be used together with an HTML UI which should hover on top of the WebGL canvas.
For this among a few reasons, I'm also trying to get rid of all of my HTML UI elements. I have a few buttons left for triggering fullscreen mode, but they will soon be gone. The initial setup is harder--it's so easy to just drop in a new HTML element--but maintaining a consistent look and feel across platforms is easier if you are using only one graphics toolkit. It also makes spinning up new projects a little easier, as again, only one UI toolkit with which to bother.
> emscripten_get_element_css_size()
The…
BrendanEich · 2024-10-29
On why no extant 1995 language and why no bytecode:
https://news.ycombinator.com/item?id=1905155
https://kripken.github.io/talks/2020/universal.html#/ (from Alon Zakai in 2020)
floatboth · 2021-12-06
42% slower only in the worst case using the slowest (explicit) bounds checks, only 12% slower with a signal handler:
https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html
Tobu · 2021-12-06
And I see the safe languages section[1] in the WasmBoxC post; that looks like it would address most of the remaining UB risk, but Firefox will take some time getting there.
[1]: https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html#safe-lang…
vidarh · 2021-04-25
wasm2c/WasmBoxC springs to mind:
https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html
flohofwoe · 2021-03-01
I'd imagine the generated code could be hardened similar to the code generated by clang ASAN, UBSAN and TSAN, and also wouldn't generate code that depends on undefined behaviour in the first place. Or you could do a little detour through WASM:
https://kripken.github.io/talks/2020/universal.html#/
In any case, that's better than shrugging off esoteric platforms, IMHO.
raxxorrax · 2020-09-09
Looks like a nice physics engine, but I wouldn't say it blows JS engines out of the water performance wise. They are surprisingly fast these days.
Ammo js:
http://kripken.github.io/ammo.js/examples/webgl_demo/ammo.html
Ammo wasm:
http://kripken.github.io/ammo.js/examples/webgl_demo/ammo.wasm.html
They can be faster, but it is still insane how fast JS interpreters have become. So for smaller application it might be ok to stay in JS land.
jamesfmilne · 2018-10-30
Documentation on how this is implemeneted in emscripten:
https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
p0peax · 2018-09-11
In WatermelonDB's case, I bet most people will run it using React Native (ie mobile apps for iOS and Android), so that wouldn't really be an issue.
On the other hand, sql.js (https://github.com/kripken/sql.js/) packs to about 2,6MB (see http://kripken.github.io/sql.js/js/worker.sql.js). I don't know about performance under heavy use of that. I don't know what SQLite backend WatermelonDB uses from ReactJS either.
jetti · 2018-09-03
You could always try using Emscripten [0] to generate Javascript from the existing C library and see how that turns out. However, I feel like it could introduce a lot of potential issues.
[0] http://kripken.github.io/emscripten-site/
mattigames · 2018-08-22
The Emscripten File System API, "The API is inspired by the Linux/POSIX File System API, with each presenting a very similar interface." https://kripken.github.io/emscripten-site/docs/api_reference/Filesyste…
wlkr · 2018-08-01
Seconding the performance issues (at least on web). For comparison, https://kripken.github.io/misc-js-benchmarks/banana/ these demos run fairly smooth for me on their highest settings.
jlebrech · 2018-04-19
you could use emscripten to compile to wasm as a target https://kripken.github.io/emscripten-site/docs/compiling/WebAssembly.h…
gnode · 2018-04-12
As far as I can tell, SFML wouldn't be appropriate. By web-based publication, I mean using the APIs supported by browsers (Canvas, WebGL, Web Audio API).
Potentially I could use Emscripten's HTML5 API ( https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.h… ). Although I was hoping for a nicer interface than calling out to a C translation of the JavaScript APIs.
billconan · 2018-01-20
yes, please read
https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_…
also debug this project and see how it controls html via c++
https://github.com/mbasso/asm-dom
logn · 2018-01-18
Rust -- https://github.com/koute/stdweb
C++ -- https://github.com/mbasso/asm-dom
I don't know exactly how these work but Emscripten allows interop both ways (embedding JS in native code and calling native code from JS) -- https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_…
MagicNumber · 2017-09-17
Mozilla has a demo for the use of WebGL which is pretty impressive: http://kripken.github.io/misc-js-benchmarks/banana/index.html
Web assembly even extends the possibilities game creators already have for creating browser-based games.
greggman · 2017-09-07
You mean other than C/C++ where you cab take advantage of 30 years of libraries ?
http://kripken.github.io/emscripten-site/
vvanders · 2017-08-09
Not publicly, the emscripten docs covers it in pretty good detail:
http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_a…
ihsw2 · 2017-07-11
Notably, with shared memory and atomics, pthreads support is on the horizon.
https://kripken.github.io/emscripten-site/docs/porting/pthreads.html#r…
Granted it may be limited to consumption via Emscripten, it is nevertheless now within the realm of possibility.
For this that cannot grok the gravity of this -- proper concurrent/parallel execution just got a lot closer for those targeting the browser.
nathan_f77 · 2017-05-28
I'm developing a game with React Native [1], and I have a single codebase that works on iOS, Android, Windows, and web (via react-native-web, although it needs a lot of work.)
I've had to write a few 'native modules' for various platforms, but it has to be platform-specific code anyway (e.g. ad networks, in-app purchases, game services)
I've been looking for a way to write some native code that I can compile to JS, and have decided to use C (or C++) with emscripten [2]. Rust or Kotlin might be fun, but I'm comfortable with C and it's easy to compile for iOS, Android (NDK), and Windows.
[1] https://sudoblock.com
[2] http://kripken.github.io/emscripten-site/
Ace17 · 2017-03-05
I don't know if this qualifies as "AAA", but the BananaBread demo is a must-see:
https://kripken.github.io/BananaBread/wasm-demo/index.html
hutzlibu · 2017-02-19
"Well since then, Chrome and Firefox have been going back and forth on which is the fastest. At this moment Firefox is a good margin faster than Chrome since their Electrolysis update."
In benchmarks, yes.
But in the real world, with many different tabs open, where one badly designed website could screw up your whole surfing experience, not so much.
Even thoug it is possible that they fied that behavior by now. I don't know, because since that repeatedly happened, I switched to chrome.
edit: oh and about specific performance I know and care about at the moment, because I work with those technologies is that:
http://kripken.github.io/box2d.js/webgl_demo/box2d.html?500
On my system (Archlinux) chromium runs much faster than firefox.
TheCycoONE · 2017-02-09
There are a few, none of them optimal for DOM manipulation yet because they all involve calling javascript. There is plans to add wasm dom hooks eventually. https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_…
corysama · 2016-11-24
I think this is what you are missing.
https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_…