40 ms·
Clang runs in the browser and compiles C++ to WebAssembly
- mark-r 9y agoSo Clang itself was compiled to WebAssembly? That's slick, even if it does take forever to load.
- ateesdalejr 9y ago2mins or so. Not bad.
- mark-r 9y ago2 minutes is truly forever on the web. I found myself wondering if there was something wrong with the page.
- okket 9y ago~20 sec in my Late 2013 MBP from page load to "The [cake] is a lie," in Chrome 63. Sadly it does not work in Safari or Safari Tech Preview, but it works in Firefox 57 (known problem, see https://github.com/tbfleming/cib https://github.com/tbfleming/cib)
- jmgao 9y agoclang is pretty big. There's about 55 MB of binaries on that page. When served from localhost, it takes about 10 seconds to load and compile a source file on my machine.
- solarkraft 9y agoThis gets us to two caching-related problems: What if you're offline and how do you decide what you want to be cached? But browser vendors will solve this.
- imtringued 9y agoIsn't this solved with progressive web apps? On the other hand I'm not aware of any UI that allows you to explicitly choose if a PWA should be cached or not.
- sitkack 9y agoWhat about packing up web assembly into a single file container like runtime designed to run server side web applications? This .war (Webassembly ARchive) file could include the application and all dependencies in a single installable that is JITd on load. Might be useful for the next generation of "serverless" cloud runtimes.
- dpratt 9y agoI see what you did there. I’d be all for this, honestly, except that the existing containers (yes, even Jetty) are too heavyweight for this use case. What you really want is a stripped down server runtime that loads and starts your application’s archive, fires it up on a (possibly random) local port and opens a stripped down Chromium instance that loads the app from that port. Of course, that sounds a bit like Electron.
- imtringued 9y agoNode.js supports webassembly.
- solarkraft 9y agoThis will probably happen. Hopefully properly compatibly.
- tzahola 9y ago>.war (Webassembly ARchive) This is sarcasm, right? If it is, it's damn good.
- stevemk14ebr 9y agoPeople might not like it but i really think native apps are going to die once everyone figures out how to optimize this crazy web stack.
- ateesdalejr 9y agoI agree, once browser get a good grip on CPU parallelism things will probably be all downhill from there.
- mark-r 9y agoHow many threads do you think the browsers will allow on a single page?
- BatFastard 9y agoAs many as is needed. And as many processors as are needed. As someone who writes browser based 3D games, I need more power!
- meritt 9y agoOut of curiosity, what technologies are you leveraging to write browser-based 3D games? Lightweight WebGL libraries, something higher-level like Unity, or something else entirely?
- BatFastard 9y agoRolling my own graphics engine (ugh!) to create a voxel octree platform. Front end uses C++ to Webassembly for the engine core and Typescript for the UX. Backend uses Java with a MSOA. All using a reactive message system.
- solarkraft 9y agoA web page should probably not be allowed to use unlimited amounts of computing power without asking for permission first.
- z1mm32m4n 9y agoI guess this just means we’re one step closer to Gary Bernhardt’s vision: https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- nitemice 9y agoEvery time something like this is posted, I always think of that video. As ridiculous and played-for-laughs as it is, it's looking more and more accurate (in one form or another) every day.
- AnIdiotOnTheNet 9y agoIf we have learned anything in the past 2 years, it is that the difference between parody and reality is vanishingly small.
- z1mm32m4n 9y agoWhat happens when the stuff like the “exclusion zone” and the war from 2020–2025 come true...? ¯\_(ツ)_/¯
- djsumdog 9y agoSo the web browser is pretty much a mini operating system. Firefox and Chromium seriously feel like they have the longest compile time out of any package in Gentoo, except maybe Libreoffice. It has tons of embedded packages that it doesn't pull from the system/native (jpeg and png decoders and such). So with a lot of these neat things where we compile stuff or run a Linux kernel in the browser, we've pretty much come full circle? It's like running cygwin in wine or an NES emulator inside of Windows 95 VM.
- ww520 9y agoI guess so far they are just a VM. Still needs to port Linux or some OS to WebAssembly to make it whole. Having the C++ compiler working is a very good start.
- solarkraft 9y agoIt'll happen. Webassembly as a Linux target architecture. It's a solution without a problem, but maybe web devs will find a way to use this to make their development easier.
- williamstein 9y agoNot WebAssembly but still fully Linux in browser- https://bellard.org/jslinux/ https://bellard.org/jslinux/
- ehnto 9y agoI have been thinking about why we have ended up here, and why not just native apps. The obvious answer is that it makes applications portable, which is great. The other key component I think is delivery. You don't ever install anything, it just exists when you ask for it. That is something native applications have never done, and not even something like JVM has done even though it addresses portability too. It is also nice that it is seamless with the browsing experience, but I have to wonder if it hasn't just turned out that the typical browser interface is a better interface for computing than most popular OS have been? As the OS and browsers start to see parity, are there lessons from browsers that we can integrate into the OS?
- deepGem 9y agoThis is really slick. Clang took about 20 secs to load on my quad core MBPro. How does this change web development ? Do we need an Ecmascript equivalent for C++ ?
- buzerr 9y agomakw
- buzerr 9y agomaw
- sehugg 9y agoClang is pretty big -- as a comparison, my Z80 IDE which uses SDCC (Simple Device C Compiler, i.e. no C++) loads about 2 MB of WASM + 2 MB of data and executes a compile/assemble/link cycle in about 0.5 sec for a small program: http://8bitworkshop.com/v2.1.0/?platform=mw8080bw&file=gfxtest.c http://8bitworkshop.com/v2.1.0/?platform=mw8080bw&file=gfxte... Most of the execution time is spent in SDCC's register allocator, which was recently rewritten to generate better code but unfortunately is a lot slower than the old allocator.
- seibelj 9y agoWhat a cool website (and book), I love what you have accomplished.
- seibelj 9y agoIdea - make a website that lets you compile and test any open source program. For example, I should be able to clone, compile, and run gedit (a stagnating text editor included with many linux distros). This would let me quickly experiment with and edit a variety of programs and tools within the web browser without needing to get a development system up and running. I bet open source projects can get a ton of new hackers to continue development on their programs if everything could be worked on quickly within a web browser.
- ychen306 9y agoIt's hard to just apply this to an arbitrary project, which may use nontrivial linker features or native code.
- seibelj 9y agoTrue. I think this would be a project within the open source community. Core libs (libXYZ) would be pre-compiled to WASM, and only the lib / program being hacked in would be modified in the browser. The compilation and linking would include the core libs. Maybe I will work on such a project, I will think about it.
- exikyut 9y agoMain issue is memory usage. Running KDE+Kate - http://vps2.etotheipiplusone.com:30176/redmine/emscripten-qt-examples/kate/kate.html http://vps2.etotheipiplusone.com:30176/redmine/emscripten-qt... - uses 1793MB (htop VIRT), 416MB (Chrome task manager). (Oh, and the renderer process wasn't hosting any other tabs.) Second main issue is speed. qsterix isn't as memory-heavy but runs all Tetris game code inside KDE JavascriptCore, which as part of the KDE/Emscripten build is transpiled to JS. In other words, http://vps2.etotheipiplusone.com:30176/redmine/emscripten-qt-examples/qstetrix.html http://vps2.etotheipiplusone.com:30176/redmine/emscripten-qt... is JavaScript inside JavaScript, and on my reasonable-but-not-last-week-new i3 box, I experience a small pause that I can't explain when I hit the spacebar to drop a block. Half of me wants to warn everyone from opening these on their phones or tablets, the other half wants to know how badly everything crashes. :P Note: I tried opening the Kate demo a week or so ago on a marginally older version of Chrome, and the download phase hung. It worked this time though.
- muthdra 9y agoenlarged memory arrays from 536870912 to 1073741824, took 28094 ms
- flavio81 9y agoThis is just fantastic. The "happy 2018!" news i was waiting for. As i've said before, little by little we're witnessing the end of Javascript dominance.
- solarkraft 9y agoWebassembly is still loaded through javascript, webassembly "apps" will be like libraries. You could compile other languages to js before, but the performance gain is really awesome.
- flavio81 9y ago>You could compile other languages to js before In the mid-term, there will be no more reasons to do that. Just compile those languages straight to Webassembly.
- Sreyanth 9y agoThis is awesome. I was planning to write one myself after I couldn't find any such Clang runner for browsers. I guess I could just strip off a few overheads so I can run some pretty small programs to teach algorithms.
- kgraves 9y agoThis is neat and shows great potential, I hope in future that Adobe products would be integrated with WebAssembly or even old products converted to WebAssembly and running in the browser. We shouldn't be that far off.
- sp332 9y agoAre you thinking like Photoshop, or a sandbox for Flash?
- mailslot 9y agoCool! Now I just need the JVM as a clang target, and then I'll never have to use anything other than C++ ever again!! :D Webassembly has a tad more promise than ActiveX.
- imtringued 9y agoPerhaps you could use node.js to compile your C++ code into a native WASM module?
- mailslot 9y agolol. Gross! Perhaps if Node.js... omg. Nevermind. You can call pthreads from Node.js. :)
- pjmlp 9y agoIt already exists. https://github.com/graalvm/sulong https://github.com/graalvm/sulong
- ttflee 9y agoEvery time I see such news, I tell myself maybe it is the time we port a browser into the Linux kernel and build METAL, like Gary Bernhardt foretold. https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- no_gravity 9y agoOr directly into the cpu. Since there already is a web server in the cpu [1], adding a browser might enable us to run and use web applications without even installing an operating system. [1] https://www.networkworld.com/article/3236064 https://www.networkworld.com/article/3236064
- ttflee 9y agoThe METAL (proposed by Gary Bernhardt) is not about running in CPU, but running all software in byte code and render native code obsolete, by implementing software process isolation and save the overhead of syscalls, memory mapping and protection rings.
- beagle3 9y agoIBM’s AS/400=eServer is basically implemented this way since 1988 years (some of it going back to 1979). Everything old is new again. (It has 128 but pointers, btw - so it’s future proof for at least 20 more years)
- fasquoika 9y agoThe original bytecode OS is AFAIK the UCSD p-System (from 1978) https://en.wikipedia.org/wiki/UCSD_Pascal https://en.wikipedia.org/wiki/UCSD_Pascal
- shalabhc 9y agoNext we'll get to a webassembly-only VM that will replace the OS. All 'apps' will run on this VM instead of being native, and most will be cross platform. They'll talk to each other via messaging (using Javascript semantics) instead of bytes-over-pipes as they do today. An integrated globally available, namespaced data store API might replace the filesystem. Each app+version will be accessible by a distinct URL. 'My computer' will finally be fully virtual - a well defined collection of 'apps/data' URLs that materializes wherever I can open one of these webassembly VMs. With this webassembly VM, early bound (precompiled) lower level languages may not have a strong advantage over late bound, dynamic ones, because the compiler is part of the OS layer (as it should be). The world seems to be slowly moving, in a roundabout way, towards the OS-browser idea from Alan Kay.
- tzahola 9y agoReplace “WebAssembly VM” with “JVM” and you will see how it’s already available, and why it won’t catch on.
- C14L 9y agoThe big difference is that the "Browser VM" has well defined permissions to access resources on the host machine. Just like phone OSes do today. Bluetooth API, Files API, Location API, etc.
- fleitz 9y agoAt which point you have an OS... except adding the word ‘webassembly’ somehow imbues it with properties OS’s don’t already because somehow web assembly compiles to assembly with extra security with no performance reduction.
- deleted 9y ago[deleted]
- int_19h 9y agoJVM had to be installed, and it was far from seamless the way OP describes it. The advantage of wasm is that all the people running Chrome today already have it.
- paulhilbert 9y agoSo we could finally port windows93(.net) to C++?
- jokoon 9y agoFinally, wasm short-circuited the will of os manufacturers to make their platform exclusive and incompatible with others. Now let's see if wasm performs well enough on Android phones, and I guess we are finally arriving into the software deployment heaven.
- Micoloth 9y agoSo the mobile part is very interesting to me, as i'm no expert on this: as cool as it is, isn't this whole webassembly thing a desktop-only thing? There is no way smartphones will be able to download compile and run this type of code at accettable speed will they? Or am i wrong?
- MaxBarraclough 9y agoAnd it only uses 400MB of RAM. Neat though.
- xtrapolate 9y agoHaving some random thoughts about the comments here, some of which talk about having a "browser" drive large parts of what we consider today an "operating system". I agree that certain aspects of what most modern operating systems do today can be abstracted away behind a unified, convenient (and perhaps browser-accessible) API. The entire user-experience stack comes to mind immediately, but there are counter examples as-well. The answer to non-unified execution environments (as in different operating systems and architectures) was the rise of high-level, interpreted languages (in addition to corresponding VMs), and runtime environments which exposed a platform-independent set of APIs. We've been exploring the possibilities of implementing bytecode VMs in hardware (https://en.wikipedia.org/wiki/Java_processor https://en.wikipedia.org/wiki/Java_processor), or running a managed code operating system (Microsoft's Midori) for a while now, so the concept itself isn't particularly new. What is WASM's advantage over, say, Java's bytecode? Did we really have to go through so many hoops (reinvent another instruction set and a VM that can execute it across multiple platforms)? Why wasn't an existing technology re-used here to achieve the same/similar goals?
- vbezhenar 9y agoI think it just happens that browser is the most widely installed VM independent of a single major vendor, pretty cross-platform and with enough features to build applications of any complexity. If you would design that from scratch, I think that something much simpler could be designed, much simpler than JVM, for example. But how would you install it to every computer out there? Nobody would use it if it's not installed everywhere.
- chuckdries 9y agoWell, what would you have replace it? Like most things that become very popular, the web is becoming an os-like platform because it solves a problem. Putting your application at a URL is hugely more accessible than asking someone to download something. Maybe not to us HN readers, but to my mom, who's skeptical to a fault of anything that says download, it's huge. HTML+CSS+JS is everywhere and complete in a way that literally nothing else is. Yeah C is everywhere but (before nowish) you couldn't write a C application once and have it run the same pretty much everywhere. But chuck, you say, HTML has notoriously bad compatibility and working with it is frustrating. I propose to you that HTML and CSS have so many compatibility problems because of how pervasive it is and has been for so long, and how many different implementations of it exist. Anything is bound to develop compatibility issues when it gets as large as the web. But you're right, it's suboptimal and other tech has tried to be everywhere. Java and Flash did try, but have you ever used a java applet? They're fine I guess, but they're stuck in a square on the page. You can make a java or flash object take up the whole page and completely control the website but then you run into accessibility issues and complexity on your part. Javascript has grown organically over the past decades for a reason, and it's being used in this fucked up way because, all things considered, it's the best platform for the job right now
- bawana 9y agoso does the concept of the 'browser is the OS' , improve security? Is it analogous to a hypervisor running on a server somewhere, then when you log into the server, it spins up a vm os just for you. Now any hacking done on that os is isolated and disappears when that instance is closed. in the same way, when the browser is the os, none of the files,apps or stuff on your machine is available to it?
- Kip9000 9y agoImpressive as it is, depressing that it enables C++ survival. C++ is a badly designed mess that gets ever more complicated and most probably the language itself is order(s) of magnitude complex than the problem you're trying to solve. Please enable other better designed comparable languages (like, D,Rust,Nim,etc..)
- singularity2001 9y agosorry for negative comment: ) it crashes Firefox ) very slow *) "1"s c_str? srsly??
- gamesbrainiac 9y agoJust tried it on Firefox, working fine. Changed the code as well, and still compiles.
- nodja 9y agoSo, until when can we build firefox and run it, in chrome?
- MobiusHorizons 9y agoNow we just need to compile a browser to webassembly so we can run a browser in a browser :) then the browser will officially be a complete operating system. On a serious note though, this is an awesome example!!
- netheril96 9y agoThere is actually an immediate real world use for this (not just being a toy): online judge (like leetcode). Of course, the final evaluation has to be done on the server to avoid cheating on the test set, but the user can do his/her own test in the browser without the roundtrip to and from the server then.
- AndrewGaspar 9y agoThis is very cool. It seems like there's some sort of memory leak, though. If you press the Run button over and over, you'll get a little message every 2*N runs about expanding memory arrays by double.
- feelin_googley 9y agoIt does not run in the browser I am using. That is one reason I chose it. Choice is good.