Live data from Hacker News

WebAssembly architecture for Go

docs.google.com

11–20 of 71 posts

Re: WebAssembly architecture for Go

#11
post #7

I'm trying to learn more about this topic and I'm curious if anyone could clarify for me -- The reason Go would need a specific architecture for WebAssembly is because Go supports features, like garbage collection, that WebAssembly does not. Is that right? Close? An oversimplification. Way off?

Follow-up question, why can't LLVM -> Web Assembly solve the problem?

It can, emscripten supports this, however the primary Go compiler doesn't use LLVM so this doesn't help really.

Re: WebAssembly architecture for Go

#12
post #6

I'm trying to learn more about this topic and I'm curious if anyone could clarify for me -- The reason Go would need a specific architecture for WebAssembly is because Go supports features, like garbage collection, that WebAssembly does not. Is that right? Close? An oversimplification. Way off?

As others have said, Web assembly is an architecture/target for C, C++, rust, etc. that you compile for, and it will be the same for go. The link does talk about GC support. It looks like wasm will have one, but go’s will most likely perform better since it is tailored to go. (edit for clarification) I assume a lot of the planning for this was in the GitHub and mailing list discussions dedicated to go’s wasm support.…

I was under the impression that WASM does not have one.

Re: WebAssembly architecture for Go

#13
post #6

Earlier quoted context omitted.

As others have said, Web assembly is an architecture/target for C, C++, rust, etc. that you compile for, and it will be the same for go. The link does talk about GC support. It looks like wasm will have one, but go’s will most likely perform better since it is tailored to go. (edit for clarification) I assume a lot of the planning for this was in the GitHub and mailing list discussions dedicated to go’s wasm support.…

I was under the impression that WASM does not have one.

IIRC, WASM doesn't have one and, more importantly, has an architecture which makes implementing one on top of WASM efficiently difficult.

Re: WebAssembly architecture for Go

#14
post #8

If you tried to look at the document and found that the entire internet has been screwing with the formatting, change "Suggesting" to "Viewing" in the top right. Seems like someone forgot to check permissions on the document.

Honestly, the defacement is at least as interesting as the original document.

Re: WebAssembly architecture for Go

#15
post #6

Earlier quoted context omitted.

As others have said, Web assembly is an architecture/target for C, C++, rust, etc. that you compile for, and it will be the same for go. The link does talk about GC support. It looks like wasm will have one, but go’s will most likely perform better since it is tailored to go. (edit for clarification) I assume a lot of the planning for this was in the GitHub and mailing list discussions dedicated to go’s wasm support.…

I was under the impression that WASM does not have one.

Wasm doesn't have one yet, but it's a future extension to to spec.

You can, of course, compile your GC in today, and it will work. Wasm's integrated support will mean re-using the existing GC, which means smaller code size.

Side note: most people thought this would be a precursor to DOM support, but the new "host bindings" proposal opens up DOM support without needing GC support, and many people believe that now the former will land before the latter.

Re: WebAssembly architecture for Go

#16
post #7

Earlier quoted context omitted.

Follow-up question, why can't LLVM -> Web Assembly solve the problem?

It can, emscripten supports this, however the primary Go compiler doesn't use LLVM so this doesn't help really.

Emscripten does, but LLVM does without emscripten too.

Re: WebAssembly architecture for Go

#17
post #8

If you tried to look at the document and found that the entire internet has been screwing with the formatting, change "Suggesting" to "Viewing" in the top right. Seems like someone forgot to check permissions on the document.

Honestly, the defacement is at least as interesting as the original document.

That's not the reason this was posted?

Re: WebAssembly architecture for Go

#18
post #8

If you tried to look at the document and found that the entire internet has been screwing with the formatting, change "Suggesting" to "Viewing" in the top right. Seems like someone forgot to check permissions on the document.

Here is a direct link [1] for easy access; maybe Dang can change the link.

[1] https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0...

Re: WebAssembly architecture for Go

#19

I'm trying to learn more about this topic and I'm curious if anyone could clarify for me -- The reason Go would need a specific architecture for WebAssembly is because Go supports features, like garbage collection, that WebAssembly does not. Is that right? Close? An oversimplification. Way off?

Garbage collection isn't really a problem because no CPU architecture supports garbage collection- the compiler is generating code to implement the GC regardless. The issue is that WASM doesn't really resemble real CPUs at all. Basically all modern CPUs are register machines, but WASM is a stack machine.

Say you have the code C=A+B in your program.

The generated assembly for a real machine looks something like this: (R* denote registers and A-C are memory addresses) load A->R1 load B->R2 add R1+R2->R3 store R3->C

WASM looks more like this: push A push B add pop C

This alone makes the approach to code generation and optimization quite different.

WASM does lack some features that you would find in real CPUs, most notably the ability for execution to jump to arbitrary memory locations. They had to work around this to maintain the behavior of goroutines. Functions also live in their own address spaces which necessitates a change to how the program counter works.

Re: WebAssembly architecture for Go

#20
> 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

I don't think it's hard to imagine reading the GC proposal. The JS collector that might be reused could be off thread, something WASM can't (yet) do.

> Most file system operations are mapped to Node.js’ “fs” module. In the browser, file system operations are currently not available.

Please please abstract this. As a maintainer of a non-JS WASM backend, I'd love to use Go too.

> Especially a “goto” operation in WebAssembly would be very helpful.

I didn't look into the Go use case enough, but curious how much better this would be than the current labeled block and labeled break approach in WASM. WASM has fairly strict stack/frame rules/types, so arbitrary gotos wouldn't work.

Post reply on HN