Skip to content

Golang Support #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
joegrasse opened this issue Apr 25, 2018 · 30 comments
Open

Golang Support #381

joegrasse opened this issue Apr 25, 2018 · 30 comments
Assignees

Comments

@joegrasse
Copy link

Will Go be supported in the future?

@thomaswue thomaswue self-assigned this Apr 25, 2018
@thomaswue
Copy link
Member

It could be possible via a Go => LLVM => GraalVM bridge. There is this project https://go.googlesource.com/gollvm/ and this project https://github.com/go-llvm/llgo. The former looks more up-to-date. We will investigate what it takes.

@eginez
Copy link
Contributor

eginez commented Apr 30, 2018

For what is worth I tried running lli with https://github.com/go-llvm/llgo and found that lli was failing to load some of the native libraries. I created a docker image that can be used for testing docker pull eginez/graalgo, fair warning is a big image(~17Gb)

@lukasstadler
Copy link
Member

Yes, the relationship between the gollvm-created bitcode and the Go runtime library is somewhat special - FWIW, even llvm's own "lli" seems to be unable to handle it.
We're looking into various ways to make that work, we may need to introduce a special hook for Go code.

@chengenzhao
Copy link

If bitcode way is not working, well maybe not that perfect
is it this project helpful?
https://github.com/PDZaninov/GoLang-Compiler
TruffleGoLang-Compiler
Contributors: Baiwen Huang, Kyle Remmert, Petar Zaninovich, Trevor Ching, Vincent Kim

This is a student project done for Oracle for CMPS 116/117 at UCSC.

Oracle’s Multilingual Engine (MLE) allows multiple languages to freely interoperate. This enables users to work with a language of their choosing when working with Oracle’s database products. The MLE relies upon the Truffle framework and Truffle languages to execute source code within the database process space. The goal of this project was to incorporate a subset of Go into Truffle’s suite of languages.

@CAFxX
Copy link

CAFxX commented Jul 16, 2018

It could be possible via a Go => LLVM => GraalVM bridge.

Wouldn't going through truffle be better than LLVM in this case? Compiled Go programs contain a pretty big/multithreaded runtime (including a user-mode scheduler tightly integrated with the garbage collector and the built-in I/O event loop) that would need to run on top of the graal runtime. Even if suboptimal going the LLVM way may work at least in simple cases (footgun number one is likely going to be the presence of two GCs) but it would be pretty unusable for anything non-trivial involving cross-language interop (that would also depend on cgo, since there's no other supported way of doing interop with the standard go runtime). With a "trufflego" approach these issues wouldn't apply - although it would require signifcant work to get them right.

(I'm gleefully glossing over the fact that going with truffle would require reimplementing a significant part of the runtime, as well as a Go interpreter -- and that therefore the amount of work is not even remotely comparable)

@eginez
Copy link
Contributor

eginez commented Aug 3, 2018

golang is about release a compiler that can target wasm, I wonder if we could use that target and load it through graaljs and have that be the interop channel with java

@ScalaWilliam
Copy link

I'm interested in this.

@psanders
Copy link

Same here!

@thomaswue
Copy link
Member

We did get more requests for this feature recently. If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

@chengenzhao
Copy link

We did get more requests for this feature recently. If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

We do have an example
currently we are using Vert.X toolkit and we hope we could use Goroutine in the verticle just like Kotlin Coroutine, which will make async code relatively easy to write.
For Kotlin Coroutine, we have to launch the coroutine scope, but in Golang, we dont have to do that, we could go keywork to simplify the async code, Java has similar feature which is Project Loom but it takes time to complete, so if we could write the code in Golang then the vertx-lang-golang/go4x would be a perfect match in this scenario.

@chengenzhao
Copy link

Vert.X has a language support based on Graal, which is es4x project
https://reactiverse.io/es4x/
and we could create similar projects to use Golang e.g. go4x
we do have many people experienced in vertx-codegen tool
so if Graal could run Go language, we could generate vertx-lang-go/go4x to wrap vertx apis
and provide these apis to Go users, for now, about green thread/fiber/coroutine etc.
Golang is the easiest way to write, we could benefits from this feature
A similar scenario is Kotlin Coroutine support which makes Kotlin code easy to write in Vert.x
e.g.
https://vertx.io/docs/vertx-lang-kotlin-coroutines/kotlin/
so we could generate a similar feature for Vert.X

@marcellanz
Copy link

We did get more requests for this feature recently. If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

@thomaswue it would lower the bar entering go applications in environments where the JVM is traditionally established, both by expertise, tooling and its operational foundation. think about companies that restrict their decision to use a language if it runs on the JVM.

@eginez
Copy link
Contributor

eginez commented Oct 25, 2018

I think a killer use case is just to leverage libraries written in Java from Go and viceversa. The java ecosystem is very rich in the open source as well as within corporations. Allowing people to run software in go(or java) without having to re-implement well tested libraries would be key feature for graalvm. This is specially true given go is gaining grounds as a backend language.

@joegrasse
Copy link
Author

My use case, and the reason I opened the original issue, was so that I can use Go to write stored programs in MySQL, instead of javascript.

@eginez
Copy link
Contributor

eginez commented May 24, 2019

Here is an experimental solution I was playing: https://gist.github.com/eginez/d69e3e1c4045eb692a274bd2bd5d31d6

@thomaswue
Copy link
Member

thomaswue commented May 24, 2019

How does this tre project compare to https://go.googlesource.com/gollvm/? I see that this was discussed further up. It seems still like this gollvm project could be a more solid way to create llvm bit code from go.

@eginez
Copy link
Contributor

eginez commented May 29, 2019

agreed the above post is demonstrative only

@spangaer
Copy link

Being able to parse a terraform script in to JVM using it's original parser implementation would be a nice use case.
;)

@eginez
Copy link
Contributor

eginez commented Dec 2, 2019

The support for WASM in GraalVM opens yet another door to run go in the GraalVM. This time through go's wasm backend.

@smasher164
Copy link

How does support for Project Loom affect the viability of a truffle implementation for the Go runtime?

@eginez
Copy link
Contributor

eginez commented Apr 4, 2021

It would surely make the implementation of go-routines much easier

@CAFxX
Copy link

CAFxX commented Apr 5, 2021

If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

One scenario is that of compute-heavy applications; the go compiler is heavily focused on compilation speed, and for this reason it is extremely conservative w.r.t. which optimizations are performed (inlining is done extremely sparingly, very little devirtualization is supported, no LICM, no TCO, no autovectorization, very basic native arch detection, and especially no support for PGO1). As a result, compute-heavy operations (e.g. gzip encoding/decoding) when implemented in go and exposed with idiomatic interfaces end up being slower.

GCC and llvmgo could help address some of these points, but IIRC they are missing higher-level go-specific knowledge about the memory allocator, GC and goroutine stacks, so they end up allocating more on the heap compared to the go compiler.

At least on paper, a truffle-based implementation of go should fare significantly better here, especially for server-like workloads where there would be plenty of time to profile and specialize the compiled code.

Another use-case is cgo, that currently is plagued by high overhead so it can only be used efficiently when the invoked native code has to do significant work. If the native code was instead compiled via sulong and the runtime implemented in truffle, the problem would potentially disappear altogether.


Update (2023-01): Yet another use-case is when doing lots of disk I/O or other blocking syscalls (excluding network-I/O related ones, that -simplifying- are transparently transformed into their asynchronous/polling variants by the go runtime) the go runtime -again, simplifying- transparently spawns threads to perform them. With loom and io_uring a graal implementation could transparently transform all supported blocking syscalls into their io_uring equivalents, avoiding the need for spawning all these threads.

Footnotes

  1. with go 1.20 this is now changing, but it will still require profile collection and a separate PGO build

@zonghaishang
Copy link

zonghaishang commented Apr 12, 2021

最近,我们确实收到了更多关于此功能的请求。如果有人想到了在GraalVM上运行Go的一些具体示例场景;例如,请分享主要的预期收益(互操作性?性能?工具?)。

@thomaswue
@lukasstadler

At present, the wasm module is supported on the go project mosn, and we hope that the wasm compiled by java can also be executed (outside the js environment).

We have implemented protocol extensions in the rpc, so we also hope that java developers can provide extension plugins.

We noticed that wasm currently supports multiple language implementations:https://github.com/proxy-wasm/spec

  • AssemblyScript SDK
  • C++ SDK
  • Go (TinyGo) SDK
  • Rust SDK

In the java compiler, no examples of use in a non-web environment have been found so far.

@dcorbe
Copy link

dcorbe commented Nov 27, 2021

LLVM supports GCC's IR. Has anyone investigated the possibility of using gccgo as a bridge?

@ShalokShalom
Copy link

The wasm backend of Go, does seem to be production ready now:

https://github.com/golang/go/wiki/WebAssembly

@ShalokShalom
Copy link

And I found also a binding to LLVM, although it speaks about a 'system-installed' LLVM, and is at least hosted by the TinyGo project, so it may provide just bindings for this subset

https://github.com/tinygo-org/go-llvm

@dgutson
Copy link

dgutson commented Jul 28, 2023

We did get more requests for this feature recently. If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

We have an SDK, with different codebases in different languages. Currently, we have to replicate the SDK into each language we support (support madness); I would like to have one SDK in one language, and use GraalVM to interop with the user code. Bindings are also a mess.

This being said, also supporting haskell would be so useful.

@ShalokShalom
Copy link

We did get more requests for this feature recently. If anybody has some concrete example scenarios in mind for running Go on GraalVM; e.g., what would be the main expected benefits (interoperability? performance? tooling?), please share.

We have an SDK, with different codebases in different languages. Currently, we have to replicate the SDK into each language we support (support madness); I would like to have one SDK in one language, and use GraalVM to interop with the user code. Bindings are also a mess.

This being said, also supporting haskell would be so useful.

I did not try it for myself, and remember people saying it does run on Graal Sulong.

The Haskell compiler has a native LLVM backend these days.

@Zireael07
Copy link

You asked for concrete examples: I have some Go scripts (image processing) - in Go because I can't write C and Go is almost as performant AND it compiles fast. But Go doesn't have good visualization libraries, while e.g. Python and Javascript do (matplotlib and d3)

@ShalokShalom
Copy link

Did you see the wasm and llvm compiler? It seems like an opportunity to run Go on Graal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests