There is no way to modify an existing rope: all operations on a rope return a new rope.
I wrote a bunch of stuff that worked this way. Some stuff that even got acquired! Thought it was nice and elegant. But each and every one of those systems failed once they got beyond trivial scale. You just can’t do Go like this. It thrashes the GC and can’t be made performant.
Incidentally do you have any recommendations for things to learn how to write fast go? My recent attempts have had very mixed success - it’s easy to write code that is much slower than naive code.
rope.go in the repository talks about persistence, but it sounds more like immutability — new, modified instance is returned for every change. Is the use of word persistence correct here, I thought it implies being written to disk or some storage?
Yeah unfortunately it seems the term is overloaded, meaning either immutable data structures or persisted-on-disk (or equivalent) data structures, depending on the author.
I wrote a bunch of stuff that worked this way. Some stuff that even got acquired! Thought it was nice and elegant. But each and every one of those systems failed once they got beyond trivial scale. You just can’t do Go like this. It thrashes the GC and can’t be made performant.
The expected maximum scale here is “human typing speed on reasonably-sized text files” and thus far seems to be okay.
Incidentally do you have any recommendations for things to learn how to write fast go? My recent attempts have had very mixed success - it’s easy to write code that is much slower than naive code.
https://dave.cheney.net/high-performance-go-workshop/dotgo-paris.html
https://granulate.io/deep-dive-into-golang-performance/
https://github.com/dgryski/go-perfbook
You, sir, are a gentleman and a scholar
rope.go
in the repository talks about persistence, but it sounds more like immutability — new, modified instance is returned for every change. Is the use of word persistence correct here, I thought it implies being written to disk or some storage?https://en.wikipedia.org/wiki/Persistent_data_structure
In this case, “persistence” means “the old versions stick around after modification as long as you need them to.”
Among other reasons, it’s a nice property because it makes undo/redo trivial.
Yeah unfortunately it seems the term is overloaded, meaning either immutable data structures or persisted-on-disk (or equivalent) data structures, depending on the author.
Nothing fancy but this is the persistent rope that I’m using in my next text editor project.
(Said text editor is going to have something really unusual, but that’s not ready to be shown yet.)
Yup! While it’s possible to go overboard with fancy rope implementations, a basic thing which gets the job done is surprisingly simple. IIUC, this 500 lines of verbose Java is what powers text in IntelliJ: https://github.com/JetBrains/intellij-community/blob/master/platform/util/base/src/com/intellij/util/text/ImmutableText.java.