10 ms·
Go gets preliminary WebAssembly support
- hasharray 8y agoThis is great; looks like it's still fairly rough but interesting that GC languages are making due with what's there in the MVP of WebAssembly right now. Wonder how it works? does it use the regular call stacks or construct it's own and so on?
- helper 8y agoThe design doc talks some about how this works: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4/edit https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0...
- _greim_ 8y agoFrom this: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4/edit https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0... > Go’s garbage collection is fully supported. WebAssembly is planning to add its own garbage collection, but it is hard to imagine that it would yield a better performance than Go’s own GC which is specifically tailored to Go’s needs. Presumably a runtime will be compiled into the wasm output, including Go's garbage collector.
- daurnimator 8y agoBut Go's garbage collector can't traverse the DOM.
- jhoechtl 8y agoA GCed language Go is with split stack semantics Webassembly will only be a second class citizen.
- recursive 8y agoThis looks like two or three sentences mashed together. I can't figure out how to parse it.
- mappu 8y agoSplit stacks are no longer used, as of Go 1.3 (2014).
- bm1362 8y agoOff topic: is it possible to build a JIT compiler for Go or does the runtime prevent that?
- mappu 8y agoI think it's certainly possible. The Go compiler is AOT and there are Go interpreters (in various stages of completeness), it would be a matter of interpreting the application - finding hot functions in execution traces - and swapping them out with background-compiled versions. Some work would be needed to keep the GC happy between interpreted and compiled functions, but no more complex than JS JITs have to do. Go's GC at least already has the capability to move objects, that's a help. In reality, JITs are used to infer typing information that dynamic languages only discover at runtime. Go doesn't have this problem, and an AOT can probably discover stronger optimizations.
- sbinet 8y agothere's actually (the beginning of) an interpreter in Go, for Go, that consummes wasm :) https://github.com/go-interpreter/wagon https://github.com/go-interpreter/wagon
- pjmlp 8y agoAny language can have a JIT compiler, that is just an implementation detail.
- crudbug 8y agoWhat are the challenges to provide a standard GC interface that all managed languages can leverage.
- jfoutz 8y agoallocation characteristics of different languages. Go copies when passing args. java is pass by value, but those values are usually pointers to objects. very different needs.
- pcwalton 8y agoTracing objects in the heap (and/or stack). The GC has to be able to find all the outgoing pointers from any object, and usually the types of the objects pointed to by those pointers as well. Different language runtimes store objects in memory in different ways.
- crudbug 8y agoI think the interface can provide the semantics - pass by reference or value etc. Which can be standardized. Then it is upto the languages to implement the interface. IMO the languages designers and developers are better off by looking at the GC solution from top-down rather than bottom-up.
- candiodari 8y agoMaybe you should think about what this would mean from the perspective of language designers. That would unearth the main difficulty of such an approach: Every language designer would have to completely redesign it's runtime system just to be able to run on this one backend (in addition to having a new compiler target and linker and debugger and ...). Hoping, of course, that this is possible at all, as many languages have various ways to store pointers to things in memory, which including not storing one at all (ie. pointer arithmetic). Why would they do this ? Why should they do this ? You could simply make the existing runtime libraries run.
- 8y ago
- misterbowfinger 8y agoHey so question - WebAssembly can't access the DOM right? What's the whole point then, avoid Javascript? If we can't just swap out all the gnarly JS garbage whole-hog, I don't see where the business value is, given that there's plenty of language-to-js libraries.
- Dayshine 8y ago>language-to-js libraries With huge performance cost and complicated toolchains.
- wvenable 8y agoWebAssembly allows you to build "native" libraries that can be accessed from JavaScript. There is huge value in that.
- deleted 8y ago[deleted]
- cjfont 8y agoSo there's a lot of other things that can be done on the client other than interacting with the DOM. In particular, applications that render intense graphics, or manage a local database could GREATLY benefit from more efficient compiled code, and this would open up possibilities that the current JS engine wouldn't be able to deliver.
- littlestymaar 8y agoThat's indeed true, but I wouldn't count Go as an example of “efficient compiled code”. It's way behind of GCC or LLVM in terms of optimizations, and being ahead-of-time-compiled is a drawback, not an asset.
- mappu 8y agoBoth GCC and LLVM can compile Go code.
- chrissnell 8y agoCould this be used to get native gRPC support for the browser?
- teraflop 8y agoWebAssembly doesn't provide any functional capabilities that aren't already accessible to JavaScript. This change does not really enable a browser to do anything more "natively" than it already could, other than run code that's written in Go.
- fnord123 8y agoWhy would you use this and not GC-free C bindings? (Clang can compile to WASM).
- kodablah 8y agoIn case you didn't see recently, https://github.com/grpc/grpc-web https://github.com/grpc/grpc-web came out of hidden-repo status recently. Of course there are caveats to its use, but I believe a server side gateway may always be needed due to how http/2 is used but I'm unsure.
- blaisio 8y agoI really wish WebAssembly did not use the word "Assembly". It doesn't really resemble any actual assembly language. And if you look at the comments in this thread, for example, a lot of people think it's letting you have something like arbitrary machine code.
- tyingq 8y agoEspecially with upcoming features like GC, threads, exceptions, polymorphic inline cache, and more[1]. Looks somewhere in between ASM and something like bytecode for a VM. [1]http://webassembly.org/docs/future-features/ http://webassembly.org/docs/future-features/
- littlestymaar 8y agoWell, ASM is a bytecode for a VM too … CPU are really complex theses days and you definetly don't run your asm on a dumb piece of silicon, as the phrase “bare metal” seams to imply. And, as a reminder, there's often bugs in that VM. Meltdown was one of them, but there's tons of them.
- pjmlp 8y agoTo add to that, that it was always how most CPUs were developed. Pure RISC CPUs were the outliers, but coupling RISC ideas with micro-code turned out to win the match. Even modern ARM versions use micro-code on their CPUs.
- tyingq 8y agoI see your point, but threading, PIC, exceptions, DOM access, etc, are a level above ASM.
- teabee89 8y agoI really wish WebAssembly didn’t use the word “Web”. Its best usecase is for the server. It just happens to also be great for challenging JavaScript in the browser.
- mappu 8y agoCan this be used with CGO_ENABLED=1 if CC is emscripten?
- caspervonb 8y agoCurrently it's not supported, see https://github.com/golang/go/blob/a9ba3e30acf004a57fbc1288d5cea6bae74d06e8/src/cmd/dist/build.go#L1359-L1399 https://github.com/golang/go/blob/a9ba3e30acf004a57fbc1288d5...
- shurcooL 8y agoIn theory (if someone does the non-trivial work), probably.
- exebook 8y agoArticle mentions that the compiled code will also run on Node.js, does it mean it will be possible to use all zillions of NPM modules from Go at some point in time?
- colonelxc 8y agoThus solving Go's dependency management problem once and for all.
- eikenberry 8y agoSolving it by giving it a worse one.
- MoOmer 8y agoThat is the joke.
- littlestymaar 8y agoWorse than pulling master on github, really ? Npm has issues, but it's still way better than the state of the art of dependency management in Go. Left-pad was bad but the problem was fixed on npm's side after a couple hours. Go's equivalent isn't fixable: https://mobile.twitter.com/davecheney/status/855049071307792384 https://mobile.twitter.com/davecheney/status/855049071307792...
- mappu 8y agoPulling master on github isn't the "state of the art" for Go (it's dep and vgo).
- littlestymaar 8y ago`dep` is pulling directly from github … And `vgo`, while promising, is still a protype not ready for production[0]. [0]: https://github.com/golang/go/wiki/vgo#current-state https://github.com/golang/go/wiki/vgo#current-state
- fredliu 8y agoHow are features like go routines and channels etc going to be supported? or they are not?
- rqs 8y agoDig a little deeper: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4 https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0... Mentions: > Currently WebAssembly has no threads, but they are on the roadmap. Most Go code can run fine on a single thread. The only drawback is that “sysmon” is not available, thus there is no preemption of goroutines.
- shurcooL 8y ago"thread" here refers to logical thread. A single logical thread can be used to run any number of goroutines, just one at a time.
- candiodari 8y agoGo does both preemptive and cooperative multitasking, so there is no relation to the number of goroutines "running" and the number of threads (or for that matter, cpus or cores). https://en.wikipedia.org/wiki/Cooperative_multitasking https://en.wikipedia.org/wiki/Cooperative_multitasking How this works in Go ? Thoroughly simplified it happens because at every flow control statement in Go, including function calls, what really happens is that, first, Go asks it's runtime to switch goroutines, and only then goes into the if, or subroutine, or ...
- shurcooL 8y agoThey are supported. Similar to how they're supported on other architectures, by having a runtime with a scheduler.
- fredliu 8y agoSo the run time is in web assembly as well, and "complied" in the final "executable"?
- oelmekki 8y agoWill the binaries be compiled for size optimization, or will they be the same size as usual golang bins? Go binaries, being static and embedding the whole go runtime, tend to be quite big. Now, I don't care about it because 5 or 10MO on my server filesystem is nothing. If I ask every visitor to download 10MO before running my webpage, that will be a problem, though. Is this something we will have to deal with? Or will this be a lesser featured go implementation?
- uluyol 8y agoI don't know much about wasm, but I imagine that most wasm binaries will be statically linked. The runtime does add overhead but I'd like to know how much compared to what you see with reasonably complex rust wasm code.
- oelmekki 8y agoYeah indeed, and if web development prefigure anything for wasm, we can expect apps to quickly have a lot of dependencies built in. I guess we'll get used again to "please wait, loading" screens :)
- pjmlp 8y agoI still get "please wait, loading" screens in JS heavy sites, specially those that go to the extreme of using JS to display static text.
- cbluth 8y agoIf you read the document link seen in the article you will see that one of their priorities is focusing on efficiency and size output of wasm.
- jayd16 8y agoHmm, maybe language runetimes can be dynamically linked and hosted by the language maintainers. Everyone imports the official library so the odds of the user already having most of everything cached is high.
- agnivade 8y agoThere are still some commits under review. I would wait until the tracking issue is closed.
- Illniyar 8y agoI thought webassembly has no GC. Is this implementing a GC for go as well, or did something change?
- TekMol 8y agoSomehow I have the feeling this whole Webassembly thing will be a giant flop. Tech people seem to think that making code run twice as fast is a huge step forward. But in the grand scheme of things its nothing.