Focus: text

Last updated 2021-09-06

So far the editor has to do these things with text:

The simplest thing we could possibly do is just store the entire text in a contiguous string. How would this perform for a 2mb text on my 2017 xeon laptop?

Wrapping per-edit means that other code in the editor that makes implicit edits (eg smart indentation) has to be careful to batch the edits to avoid triggering line-wrapping multiple times. This is pretty easy in a small project, but an editor with a lot of 3rd party plugins might want to code more defensively.

The performance tradeoffs here are interesting. If we used a more complex data-structure for the text inserts would become faster but iteration would become slower which means that eg line-wrapping might become too slow to do from scratch on each edit and we would have to do some more complicated incremental algorithm.

In the large files branch I did just that - I got nerd-sniped into trying to handle files up to 1gb which may not contain any newlines (eg minified js/html, json state dumps). It increased the line count of the project by about 30% for a fairly niche use-case, added a number of tricky bugs and complicated all downstream code.

There is a substantial benefit to insisting on simple data-structures / algorithms, even at the cost of excluding some potential use-cases.