TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why CRDT didn't work out as well for collaborative editing xi-editor

457 点作者 UkiahSmith大约 6 年前

16 条评论

tomsmeding大约 6 年前
Relevant discussion from a couple of days ago: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19845776" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19845776</a>
chubot大约 6 年前
I don&#x27;t have much experience in this area, but I&#x27;d be interested in an overview of how different pieces of sofware handle the concurrent &#x2F; multiplayer editing problem, like:<p>- Etherpad<p>- Google docs<p>- Apache &#x2F; Google Wave (open sourced: <a href="http:&#x2F;&#x2F;incubator.apache.org&#x2F;projects&#x2F;wave.html" rel="nofollow">http:&#x2F;&#x2F;incubator.apache.org&#x2F;projects&#x2F;wave.html</a>)<p>- repl.it <a href="https:&#x2F;&#x2F;repl.it&#x2F;site&#x2F;blog&#x2F;multi" rel="nofollow">https:&#x2F;&#x2F;repl.it&#x2F;site&#x2F;blog&#x2F;multi</a><p>- figma <a href="https:&#x2F;&#x2F;www.figma.com&#x2F;blog&#x2F;multiplayer-editing-in-figma&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.figma.com&#x2F;blog&#x2F;multiplayer-editing-in-figma&#x2F;</a> (image editing rather than text editing)<p>So is the gist of it that OT relies on central servers and they all use OT rather than CRDT? That was not entirely clear to me.<p>Looking at the xi analysis, it sounds like &quot;IME&quot; is specific to a desktop application using X (?), so it doesn&#x27;t apply to any of this web software.<p>The rest of them seem like they do apply?<p>Is the problem that you have to pay a &quot;CRDT tax&quot; for every piece of state in the application? I thought the same was true of OT. Don&#x27;t you have to express every piece of state within those constraints too?<p>repl.it doesn&#x27;t seem to have a problem with syntax highlighting or brace matching (try it, it&#x27;s pretty slick). So is it just that they paid that tax with a lot of code or is there something else fundamentally different about xi vs. repl.it ? Or maybe xi is going for a lot lower latency than web-based editors?<p>recent thread about OT vs. CRDT that might be interesting: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18191867" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18191867</a>
评论 #19887534 未加载
评论 #19887426 未加载
评论 #19887431 未加载
评论 #19887323 未加载
评论 #19887358 未加载
评论 #19887283 未加载
评论 #19887517 未加载
评论 #19890305 未加载
lewisl9029大约 6 年前
&gt; Indeed, the literature of CRDT does specify a mathematically correct answer. But this does not always line up with what humans would find the most faithful rendering of intent.<p>This is a very salient point that anyone thinking of using CRDTs to &quot;solve&quot; synchronization in an user-facing application needs to take into consideration. Yes, CRDTs will guarantee that clients converge to an identical, mathematically &quot;consistent&quot; state eventually, but there&#x27;s no guarantee whether or not that mathematically &quot;consistent&quot; state would make any sense to the application business logic that needs to consume that state, or to the human that needs to reason about the rendered result. That is a completely different can of worms that we&#x27;ll still have to tackle to build a usable application.<p>Here&#x27;s great example to illustrate this from Martin Kleppmann&#x27;s talk on this topic: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;yCcWpzY8dIA?t=2634" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;yCcWpzY8dIA?t=2634</a><p>Rest of the talk is also highly recommended for anyone interested in an approachable primer on CRDTs.<p>The trade-offs to CRDTs mentioned by the author in the context of text-editors make sense, but I would be curious to hear from the Xray team on what their current thinking on the topic is, given that they have collaborative editing as an explicit core objective (which might shift the value prop in favor of using CRDTs relatively speaking since in Xi it seems to be only an aspirational goal), and that their approach to implementation was similar but not quite identical to Xi&#x27;s:<p>&gt; Our use of a CRDT is similar to the Xi editor, but the approach we&#x27;re exploring is somewhat different. Our current understanding is that in Xi, the buffer is stored in a rope data structure, then a secondary layer is used to incorporate edits. In Xray, the fundamental storage structure of all text is itself a CRDT. It&#x27;s similar to Xi&#x27;s rope in that it uses a copy-on-write B-tree to index all inserted fragments, but it does not require any secondary system for incorporating edits.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;atom&#x2F;xray#text-is-stored-in-a-copy-on-write-crdt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;atom&#x2F;xray#text-is-stored-in-a-copy-on-wri...</a>
评论 #19889631 未加载
评论 #19890256 未加载
laughinghan大约 6 年前
@dang, can we edit the title? It&#x27;s inaccurate. This post is about how the CRDT didn&#x27;t work for <i>asynchronous</i> editing by automated tools like syntax highlighting, automatic bracket balancing, etc. The post explicitly contrasts those use cases with collaborative editing as a use case that the author <i>didn&#x27;t</i> implement, but where they think &quot;the CRDT is not unreasonable&quot;.
coldtea大约 6 年前
Maybe first build a capable editor, with plugins, etc (xi-editor is not that yet) and worry about &quot;collaborative editing&quot; later?<p>And even for that, I think simply &quot;taking turns&quot; (where users share an editor session, can chat with each other, and can switch on sequentially who gets to actively edit) is enough for 99% of cases, and is not more difficult than mere single-person editing (since there are no conflicts).
评论 #19888633 未加载
评论 #19888697 未加载
评论 #19889020 未加载
评论 #19889176 未加载
lucb1e大约 6 年前
At the risk of asking a stupid question: is there a reason other than offline support why we bother with conflict resolution algorithms?<p>Every time concurrent editors come up, one of the main points of discussion is the pros and cons of different possible conflict resolution algorithms. People seem to be spending a <i>lot</i> of time on debating and implementing that. The way I see it, whichever packet reaches the server first gets applied first. Send something like &quot;line 9 column 19: insert &lt;Enter&gt;&quot;, and when another client whose cursor is on line 15 receives that, it moves the cursor down to line 16 and scrolls the view down one line. Because you can see each other&#x27;s cursors and selections, it shouldn&#x27;t be hard to avoid typing in the same place. Unless you have round trip times of multiple seconds (satellite uplinks maybe?), and unless you edit continuously with more than, say, one people per ten sentences, you should hardly ever need it, and if it happens, the person editing will notice within two seconds and just wait a second for the other to finish. It&#x27;s not as if you can reliably apply edits anyway: as the article already describes, changing a line from ABC to EFG concurrently with someone modifying B to D, does not really have a good outcome. In a more realistic example, it would be changing &quot;its&quot; to &quot;it&#x27;s&quot; concurrently with changing the word to &quot;that&quot;. There is no good solution (the server wouldn&#x27;t know which person to ignore: the apostrophe inserter or the replacer), so someone will have to resolve it manually anyway, so why bother with complex resolution algorithms? Heck, I&#x27;d be fine if my editor would do exclusive locks for the line I&#x27;m on before I can start typing.<p>For slow things like the customer report, internal documents, code, etc., I use something like git. Collaborative editing is (to me) for realtime things like jotting down notes about what I&#x27;m working on and looking at what others are working on right now, where even a proper revision control system is too cumbersome (git pull, vim notes.txt, small edit, :wq, git commit, git push, repeat) because someone might be working on the same thing. In such a case, where I need to work together on a file in real time, I&#x27;m not working offline, so this conflict resolution is by definition unnecessary. Is that different from the majority of people that use collaborative editing?
评论 #19888497 未加载
评论 #19888435 未加载
评论 #19888244 未加载
评论 #19888389 未加载
nicodemus26大约 6 年前
I think CRDTs would make much more sense in a projectional editor than a text one. When the changes are mutations to the abstract syntax tree its more well defined how a merge would end. Also, the merge results don&#x27;t have the opportunity to be invalid syntax.
评论 #19893724 未加载
catpolice大约 6 年前
&quot;For syntax highlighting, any form of OT or CRDT is overkill; the highlighting is a stateless function of the document, so if there&#x27;s a conflict, you can just toss the highlighting state and start again.&quot;<p>I first became interested in CRDTs in a case where this wasn&#x27;t really true. I was writing an IDE for a custom in-house DSL - think of the application as a special language for interacting with a gigantic and very strange database. Basically, the problem was that the use case really stretched the bounds of what is normally done with syntax highlighting. Some requirements:<p>- It had syntax and semantic highlighting, where the visual feedback associated with a term would depend on the results of queries to the remote database<p>- It had to be able to handle documents of several megabytes (and many thousands of terms) fairly smoothly, with as little noticeable lag or flicker as possible<p>- It couldn&#x27;t swamp the database with unnecessary requests<p>- The document itself had implicit procedural state (e.g. if you wrote a command that, if evaluated, would alter the state of a term on the database, appearances of that term later in the document needed to be highlighted as if those changes had already been applied)<p>So I definitely couldn&#x27;t throw out metadata and start over with every change. I ended up with a kind of algebraic editing model that allowed me to put bounds on what needed to be updated with every edit and calculate a minimal set of state changes to flow forward. It was extraordinarily complicated. I never got around to learning enough about CRDTs to determine if they&#x27;d be simpler than the solution I came up with, but they do seem to target some similar issues.
评论 #19888894 未加载
hansjorg大约 6 年前
I&#x27;m assuming CRDT refers to conflict free replicated data type: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Conflict-free_replicated_data_type" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Conflict-free_replicated_dat...</a><p>OT, operational transformation: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Operational_transformation" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Operational_transformation</a>
评论 #19887265 未加载
colemickens大约 6 年前
Thank you for writing this up Raph. I&#x27;ve been following CRDT usage in Xray&#x2F;Xi and am curious to see where collaborative editing goes. I appreciate you thinking about it upfront.
lacampbell大约 6 年前
Having a bit of difficulty following this, so I&#x27;ll break down my understanding of CRDTs and see if someone can help me out.<p>A CRDT can be thought of as an algebraic structure, consisting of data type D, and a join function. So for all a, b, c in D, it&#x27;s:<p>Associative:<p><pre><code> join(a, join(b, c)) == join(join(a, b), c) </code></pre> Commutative:<p><pre><code> join(a, b) == join(b, a) </code></pre> Idempotent:<p><pre><code> join(a, a) == a </code></pre> Partially ordered:<p><pre><code> if join(a, b) == b then a &lt;= b a &lt;= a == true if (a &lt; b) and (b &gt; a) then a == b if (a &lt;= b) and (b &lt;= c) then (a &lt;= c) </code></pre> So given all of that, I am not sure why the example in the article holds. I assume it&#x27;s a consequence of the partial ordering, but I don&#x27;t know what the partial ordering is. What&#x27;s the join operation and what&#x27;s the data type?
评论 #19889163 未加载
josephg大约 6 年前
I replied with my thoughts to the github issue, but they might be of interest to people reading along here too. I&#x27;ve got some experience on these systems (wave, sharejs, sharedb, etc).<p>&gt; As a side note, I&#x27;ve heard an interesting theory about why CRDT-type solutions are relatively popular in the cloud. To do OT well, you need to elect a centralized server, which is responsible for all edits to a document. I believe the word for this is &quot;server affinity,&quot; and Google implements it very well. They need to, for Jupiter-style OT (Google Docs) to work.<p>You don&#x27;t need to do this. (Although I&#x27;m not sure if we knew that on the wave team). You can implement an OT system on top of any database that has a transactional write model. The approach is to enter a retry loop where you first try to apply the operation (but in a way that will reject the operation if the expected version numbers don&#x27;t match). If an error happens, fetch the concurrent edits, transform and retry. Firepad implemented this retry loop from the client, and it worked much better than I expected. Here is a POC of a collaborative editor on top of statecraft - <a href="https:&#x2F;&#x2F;home.seph.codes&#x2F;edit&#x2F;test" rel="nofollow">https:&#x2F;&#x2F;home.seph.codes&#x2F;edit&#x2F;test</a> . The only OT code on the server is this middleware function:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;josephg&#x2F;statecraft&#x2F;blob&#x2F;b6a82f34268238c90a8b3e600ea39ad1558cd12b&#x2F;core&#x2F;lib&#x2F;stores&#x2F;ot.ts#L36-L110" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;josephg&#x2F;statecraft&#x2F;blob&#x2F;b6a82f34268238c90...</a> .<p>In my experience the reason why semi- or fully- centralized systems are popular in products like google docs is that they&#x27;re easier to implement. Access control in a decentralized system like git is harder. Gossip networks don&#x27;t perform as well as straight offset-based event logs (kafka and friends). And if you have a canonical incoming stream of edits, its easier to reason about.<p>---<p>&gt; I have a stronger conclusion: any attempt to automate resolving simultaneous editing conflicts that, e.g., git merge could not resolve, will fail in a way that fatally confuses users.<p>I think you have to act with intent about what you want to happen when two users edit the same text at the same time. There are basically 2 approaches:<p>1. Resolve to some sort of best-effort outcome. (Eg &quot;DE F G&quot; or &quot;E F GD&quot;)<p>2. Generate an error of some sort (eg via conflict markers) and let the user explicitly resolve the conflict<p>As much as it pains me to say, for code I think the most correct answer is to use approach (1) when the code is being edited live and (2) when the code is being edited offline &#x2F; asyncronously. When we can see each other&#x27;s changes in realtime, humans handle this sort of thing pretty well. We&#x27;ll back off if someone is actively editing a sentence and we&#x27;ll see them typing and let them finish their thought. If anything goes wrong we&#x27;ll just correct it (together) before moving on. The problem happens when we&#x27;re not online, and we edit the same piece of code independently, &quot;blind&quot; as it were. And in those cases, I think version control systems have the right approach - because the automated merge is often wrong.<p>(More: <a href="https:&#x2F;&#x2F;github.com&#x2F;xi-editor&#x2F;xi-editor&#x2F;issues&#x2F;1187#issuecomment-491551004" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;xi-editor&#x2F;xi-editor&#x2F;issues&#x2F;1187#issuecomm...</a> )
EGreg大约 6 年前
From these comnents it seems that OT requires a central server while CRDT can have a far more flexible topology. Is this true? And don’t we have robust implementations of CRDT for simple trees?
评论 #19889832 未加载
microcolonel大约 6 年前
I think it would be interesting to let the language mode control the rope, or delegate subtrees of the rope to a mode. This way, you could represent things like lexical scope in the tree of the rope, and a language-specific tokenizer could further reduce the complexity of syntax formatting.<p>Emacs has the concept of &quot;faces&quot;, and many Emacs major modes have proper parsers, lexers, and even some static analyzers that they use to apply the faces. If the rope resembled the AST, then many of the issues Raph talks about could be greatly reduced by localizing edits to their area of influence. If you edit inside a token, and somebody else deletes that whole token, then it is pretty clear how to resolve that. You could conceive of natural language modes which produce humanistic hierarchies, or modes with internal formats other than text (which may have a cached text view on them) like spreadsheets or debuggers.
marknadal大约 6 年前
TLDR;<p>CRDTs cannot be &quot;bolted ontop&quot;.<p>----<p>I really don&#x27;t like this answer, but it is sadly true - even as an expert in the space (my database <a href="https:&#x2F;&#x2F;github.com&#x2F;amark&#x2F;gun" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;amark&#x2F;gun</a> is one of the few CRDT-based systems out there). And there is a simple reason for this:<p>Distributed systems are composable, they can be used to build higher-level strongly consistent systems on top. (Note: Sacrificing AP along the way, but then you can have a &quot;tunable&quot; system where each record you save you decide what consistency requirement you need, fast or slow.)<p>However centralized systems are not composable, you can&#x27;t go &quot;down&quot; the latter of abstraction by adding more stuff.
评论 #19888332 未加载
atheowaway4z大约 6 年前
Parsing &amp; syntax highlighting before CRDT might give better results