Making a Golang port

Hey all, thanks for the awesome work on this project. I would like to implement something similar to this C# port but for Golang. My knowledge of CRDTs is rather limited so I wanted to ask what specific literature/resources I should consume before starting, and if there are any other gotchas or nuances I should know.

Thanks!

I was looking into that as well, but gladly finally didn’t have to implement it. It seems like quite an effort, especially if you want to reach the same degree of optimization.

  1. Read the internals document in YJS, and watch the video linked in the beginning: yjs/INTERNALS.md at main · yjs/yjs · GitHub
  2. Watch Braid Meeting 10 and 14 where Seph explains a lot about CRDTs and how they work, comparing YJS and Automerge: https://braid.org/meeting-10, https://braid.org/meeting-14. Watch anything you can find from Seph :slight_smile:
  3. Watch anything you can find from Martin Kleppmann, he also explains very well all of this stuff. Watch his presentations of Automerge.
  4. Keep in mind that strings in JS are UTF-16 and in Go they are UTF-8, so YJS’s concept of length for string items will not be compatible with native Go strings. You’d probably have to convert them to UTF-16 or do some other trickery. YJS keeps strings as UTF-16 at runtime, and converts them to UTF-8 during encoding.
  5. Beware that YJS has 2 different encoding formats (v2 is more compact), so you have to decide on whether to implement both, or only one of them.
1 Like

Awesome thanks! I’ve already checked out the Y.js internals document and I watched a few Martin Kleppman videos on CRDTs and watched his course on distributed systems. The Braid meetings look great, will definitely give them a watch.

And thank for the heads up on the discrepancy between Go’s and JS’s string encoding, my final goal is to build a Y.js websocket server in Go… so the interoperability between the two languages is important.

Right now I’m naively porting the JS code to Go, as close to the original as Go allows. Mostly as an exercise to become acquainted with the codebase. It’s obviously not the best way of doing things, but hopefully I can get a minimal working version out soon. Cheers

Good luck with that! Hope you’ll share your findings here or elsewhere.

1 Like

If you have a repo going would love to help.
I am using tinygo to cross compile to wasm and then building the gui with golang and gioui.

my github handle is “gedw99”

to make web sockets calls between the client and the server, need to use https://pkg.go.dev/nhooyr.io/websocket. Its the only one that works with golang wasm.
works great with gioui too.
with golang types on both sides its really nice.
and debugging is easy.