News for hackers. Stuff that matters.
Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @10:19AM (#29000718)
> “Distributed state is so fundamentally complex that I think we actually need CRDTs (or something like them) to reason about it effectively.”

Gamedevs working on multiplayer FPSs and MMOs (which requires resolving incredibly complex state synchronizations at millisecond-scales) have done this for decades, and they haven’t been using any fancy CRDTs. Maybe they might have some ideas on how to achieve fast document synchronization as well?

If you forget about P2P and only think about server/client type connections (since P2P doesn’t give you that much advantages in a Google-Docs type service), I think there’s a lot of overlap between multiplayer games and collaborative document editing, and maybe some cross-domain pollination might be needed to solve this problem.

Re:CRDT resources by hesdeadjim on Tuesday October 26, 2021 @11:05AM (#29001292)
Realtime multiplay state sync isn't remotely like CRDT, it's an endless series of hacks where you attempt to send as little data as possible to have the best player experience as possible. Total smoke and mirrors.

It's fantasy to assume a client has any real "truth" about the world over the span of milliseconds, and in practice you want the client to be as ignorant as possible because cheat programs will let people see through walls, see across the map, etc.

You compensate through speculative prediction to try and make things like movement or gunshots feel lag-free, but again it's smoke and mirrors and a hundred things can cause that to go wrong. How do we resolve mis-predictions to the player? Hide it as best as possible through VFX is a great technique, or hope the users don't notice that a couple of their bullets had exactly zero effect because the server decided you shot outside the rollback buffer and didn't actually hit that other player.

It's very game-dependent too. Valorant hits a 120hz tick rate through insane optimization, and if you have a low-latency connection your view of the world will be much, much more in sync with truth compared to a game like PubG that early on had a tick rate around 15hz (oof).

It's always been a bucket list gamedev goal of mine to work on realtime multiplayer, but after a couple years of doing it I find myself fantasizing of a world where everyone is playing on a computer that isn't a potato with a connection that isn't jittery.

Re:CRDT resources by jitl on Tuesday October 26, 2021 @12:04PM (#29002111)
The major difference in constraint is how much user intention/data it's acceptable to discard, especially when a user message arrives later than expected.

In a multiplayer game, it's fine to discard all user intention that arrives a few minutes "late" - gameplay has moved on, and the client should discard local state and just use the server state. But this is totally unacceptable for a text editing application.

CRDTs or Operational Transforms are strategies that allow accepting user edits and preserving their intention even if the user is days or weeks behind or diverged from the server state. I'm not aware of a real-time multiplayer game that allows such high latency for user input.

I like this talk on Overwatch's data model (entity-component-system model) https://www.gdcvault.com/play/1024001/-Overwatch-Gameplay-Ar... - the discussion of netcode starts at timestamp 22:30

Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @12:34PM (#29002516)
So the primary reason of CRDTs is to enable offline editing?

The issue is, I don't think CRDTs will help with offline editing either. If the user edits are days / weeks behind and the documents have severely diverged, then merging two documents becomes less of a theoretical logic problem and more of a pragmatic domain-specific problem that might even require the input of the user (like a merge-tool). CRDTs will ensure that the output is deterministic and correct, but it will not guarantee how "natural" or "reasonable" the output will look, and I think you would have to eventually use a bunch of clever heuristics or even provide a mergetool for the user to cleanly resolve differences.

Re:CRDT resources by jitl on Wednesday October 27, 2021 @02:09AM (#29010050)
> offline editing

I guess, offline is relative? Most games I play consider >300ms ping to be offline, but I should be able to edit a document with >300ms ping. That said, a lot of CRDT research is focused on totally local, peer to peer editing.

> it will not guarantee how "natural" or "reasonable" the output will look

I don’t think your assumptions are correct. CRDT algorithms designed for text structures like those used by Automerge (RGA) or Y.js (YATA) do a good job preserving user intent even for concurrent edits to a text. Users won’t end up with the letters in a sentence interleaved, and it’s actually pretty rare in to encounter concurrent insertions at the same position - those are the most troublesome for both time complexity and intention preservation. Most other kinds of document edits - like edits on a order of paragraph items - are much easier.

Re:CRDT resources by whizzter on Thursday November 04, 2021 @02:16PM (#29110685)
Everything is "possible" in terms of mapping but CRDT's requires one to reformulate problems and it makes a whole lot of things more complicated without really solving GAME sort of problems.

That said I think games are in many cases behind (except fighting games because they care a bit more about outcome accuracy), I think a big part of it is that most rely on pre-made physics systems that might be impressive at rolling around particles and ragdolls but are not designed for multiplayer games to the slightest so they kinda start blowing up when you start mucking around with their states (I suspect this is why fighting games are ahead imo since they often has bespoke essentially 2d sims).

I actually implemented a coop multiplayer prototype over WebSockets for a wolf-style raycasting FPS game I had made for 7dfps that was based on OT (like many fighting games are). It's fairly simplistic (if you bring over the collision and physics work inside the OT simulation).

OT was a good choice since it would eliminate desynchronization issues, and since I was using websockets that are reliable and but can have some lag getting things reliable from the get-go was a better option.

---

1: The server runs a single truth state a second or so back in time (sent over to clients upon connection). The server never re-simulates anything (clients will, see below)

2: The server keeps a log of events back to the truth cutoff point, once the truth cutoff is passed they're not needed by the server anymore (unless some laggy client hasn't received them yet, but if that clients goes too far behind it should be dropped so no issues for the server about overflowing).

3: Upon connecting clients synchronize time with the server before receiving state and all existing messages.

4: New game states are produced immutably from the previous (with any messages tied to the point in time).

5: When shooting,etc the client sends a timestamped message to the server, the server MIGHT elect to discard or re-time any message a client sends before logging and broadcasting (this is why the time synchronization earlier was important, clients should be created at the "now" point in time or might be re-timed by the server to deter hacking).

6: A client keeps all states between the truth and now, the server will inform clients as the truth moves forward in time so they can discard old states, any message can come from the server as being timed between truth and now and all "old" messages causes a rebuild of states between the message time and "now" (The "now" state is what we display to the user)

7: A client display-cache synchtonizes with "now" and renders, if a server sent "old" messages that caused an enemy to change direction back in time the cache will handle tweening or snapping (and this is totally separated from the simulation).

Since the client created a message at "now" it would've been sent directly to the display cache (and triggered immediate feedback to the user), past changes by the server can undo things (f.ex. if you just died before shooting) but handling that smoothly is not related to the simulation code that can remain clean but rather the display cache handler.

---

Sadly I only did this as a side-project and some contracts took over so it's been kinda bit-rotting after I left it mid-refactor (it was kinda messy and tied to the game it was written for), but the architecture felt quite stable once working (one minor issue might is that it works best with fixed-point math due to floating point numbers potentially diverging, even if gradual checkpoints by the server could be introduced).

Re:CRDT resources by User23 on Tuesday October 26, 2021 @10:44AM (#29001040)
> Gamedevs working on multiplayer FPSs and MMOs (which requires resolving incredibly complex state synchronizations at millisecond-scales) have done this for decades

No they haven't. Servers crash and players drop all the time, and many things otherwise don't always act as intended. But practically it doesn't matter because nobody, not the developers and not the players, cares about whether or not their FPS is byzantine fault tolerant.

Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @11:28AM (#29001581)
I mean, they aren't perfect, but you've got to admit they were solving a hard problem with immense technical constraints. And they certainly care about robust synchronization, since subpar netcode can absolutely determine the success or failure of certain types of games (shooters, fighting games). Players always whine about netcode all the time, although 100% byzantine fault tolerance is not the goal.

Speaking of which, do you really need byzantine fault tolerance in a document editor? I mean, it would be really great if it were possible, but given the vast number of different operations you can perform in a document it seems like a really daunting task to do so both formally and practically. And Google Docs isn't really comparable to Bitcoin or airplane control systems anyway. Perhaps temporary periodic backups (like saving diffs to documents in 5-second intervals for a recent period window, so you can rollback if things seriously fuck up) as an escape hatch would be good enough?

Re:CRDT resources by dboreham on Tuesday October 26, 2021 @10:34AM (#29000932)
> they haven’t been using any fancy CRDTs

CRDT is actually "the tricks we have always used + math to prove whether they work or not". Read the papers. You'll find old school stuff like Lamport Clocks.

Re:CRDT resources by phailhaus on Tuesday October 26, 2021 @01:58PM (#29003794)
> Gamedevs working on multiplayer FPSs and MMOs (which requires resolving incredibly complex state synchronizations at millisecond-scales) have done this for decades

...no they haven't? Those aren't distributed systems. There is an authoritative server that holds the source of truth, and players sync up with it.

A truly distributed game would have each game client contain the full world state, and would synchronize with every other player rather than an authoritative server.

Re:CRDT resources by sunny--tech on Tuesday October 26, 2021 @10:43AM (#29001026)
This is only tangentially related to your point, but Riot uses CRDTs for their chat system.

https://technology.riotgames.com/news/chat-service-architect...

Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @11:11AM (#29001369)
Maybe CRDTs are useful for implementing chat systems since the operational semantics for it are simple enough to make a CRDT system for it?

The blog post I've read in the first link seems to say that CRDTs gets very complex when applying it to a domain where there are all kinds of different rich operations. I guess CRDTs aren't fundamentally the right solution for the collaborative document editing problem then?

Re:CRDT resources by nivenkos on Tuesday October 26, 2021 @10:27AM (#29000844)
If you drop the P2P requirement, you can use Operational Transformations - https://en.wikipedia.org/wiki/Operational_transformation
Re:CRDT resources by remram on Tuesday October 26, 2021 @12:01PM (#29002060)
Those games have an authoritative central server, so using OT or something akin to OT is trivial.

Even in P2P games or games with a weaker server, a given entity is owned by a single machine. This is a much simpler setup.

Re:CRDT resources by dnautics on Tuesday October 26, 2021 @11:24AM (#29001529)
Not really a CRDT UseCase. Gamedev needs A<=>S and B<=>S, where S is a central server.

CRDT is:

A<=>B A<=>C B<=>C A<=>D ...

Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @11:33AM (#29001661)
First of all, why do you need serverless P2P on a collaborative document editor? I can't really think of any substantial benefits of doing so.

And If you're actually worrying about centralization, then why can't one user run the server as well as the client (which, reading some posts about CRDT performance, should be faster than the overhead of maintaining CRDTs anyway?)

Re:CRDT resources by dnautics on Tuesday October 26, 2021 @12:01PM (#29002069)
Latency.
Re:CRDT resources by cyber_kinetist on Tuesday October 26, 2021 @12:38PM (#29002592)
Isn't the latency about the same as P2P if a single user is hosting both the server and the client?