5 ms·
Simple diet tricks for asm.js
- _RPM 10y agonit: the C style example, should use /* These kind of comments */ not // these kind of comments.
- steveklabnik 10y agoC99 supports //.
- _RPM 10y agoC89 standard does not.
- rahkiin 10y agoIt is 2016. Why evolve a language if you can't use any the new features?
- coldtea 10y agoSo? If you're still using C89 you're doing it wrong.
- _RPM 10y agoPerhaps, portability?
- spc476 10y agoMostly Windows. It's only recently that Microsoft reluctantly (and only recently) acknowledged the existence of C99 (which isn't fully compatible with C++, their preferred development language). So maybe in three more years we'll all be able to move to C99.
- rbran 10y agoasm.js really seem to be a good solution, I hope some day it will be used to do more than web games. But at the same time, the vision of the future of compiling everything in javascript is pretty scary.
- nawitus 10y agoI think WebAssembly will replace asm.js soon.
- hackcasual 10y agoThink of WebAssembly as a binary encoding of asm.js. You'll be able to deliver the same program in either format. Asm.js will still be around to support older browsers.
- jakub_h 10y agoI sort of think about it the other way round, actually.
- hackcasual 10y agoNot sure what you mean? Asm.js was defined a couple of years before Web assembly
- jakub_h 10y agoYes, but it was defined after actual assembly/low level languages like BLISS. So it was defined as a way of doing something "assembly-like" (or BLISS-like, or BCPL-like) in an environment that didn't allow for such code.
- nawitus 10y ago> Asm.js will still be around to support older browsers. I don't see a need for this since WebAssembly will provide a polyfill.
- Exuma 10y agoCan someone ELI5 what asm.js is? I've tried Googling it multiple times now and every time I basically give up because I can't relate to anything it's talking about when all they use is buzzwords.
- kevinwang 10y agoA language which is a strict subset of JavaScript. The purpose is to write compilers from C to asm.js, which then allows you to write C code and it compiles to something that can run on the browser
- teamhappy 10y ago... and that strict subset of JS can be compiled into very efficient native code.
- Saltor 10y agoThis (funny and accessible, don't worry) talk by Gary Bernhardt is what helped me understand asm.js for the first time: https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- hackcasual 10y agoThe ELIMINATE_DUPLICATE_FUNCTIONS support was contributed by Tableau Software, by the team I'm on. It's quite expensive processing wise, but is worth a shot seeing if your code base benefits from it. Our usecase leverages a lot of shared pointer based templated classes, which tends to create a lot of delete functions that boil down to free(this); 2 other points I'd add to this overall: 1) Can't emphasize enough how bad exception support is for size, expect in the neighborhood of 30% size increase. This is due to needing to handle all of the possible ways functions can return. Even with exception support disabled, you can still throw them, you just can't catch them in C++ land. 2) goto's. There's a few good reasons to use these, especially in code that needs to make sure cleanup code always runs. Emscripten supports that with a couple different code constructs, pretty much all of which cause a significant amount of bloat. We've saved ~100k in some cases by specifically targeting some 3rd party code that made use of them and rewritting them to not have gotos.
- vmorgulis 10y ago> Even with exception support disabled, you can still throw them, you just can't catch them in C++ land. Is something printed in the console under emscripten if an exception is thrown?
- hackcasual 10y agoIt gets converted into a Javascript exception, which will at least give you the Emscripten converted function it was thrown in.
- vmorgulis 10y agoInteresting. Thank you.
- jakub_h 10y agoThose recommendations together almost sound like "write C in C++".
- TazeTSchnitzel 10y agoA lot of C++ coding styles do something like that. I guess because C++ is so large.
- olig15 10y ago"The emscripten version is even smaller than the native version after compression, impossabru! I actually didn’t expect this myself (last time I did such comparisons the emscripten versions came out about 10..20% bigger)" This is because JavaScript is alpha-numeric and is easier to compress than binary. There are a relatively 'small' number of characters in the alpha-numeric range, so they can be mapped together easier than the wider range of binary data.