3 ms·
The simplest approach is to just use a large string or array of lines. However these each suffer from poor performance as either the size or line length of text
by userbinator 3y ago
The simplest approach is to just use a large string or array of lines. However these each suffer from poor performance as either the size or line length of text increases.
Every time this point comes up in the design of text editors, I feel compelled to mention that memory bandwidth is dozens of GB/s on modern hardware; even when it was only a few MB/s a few decades ago, text editors that used a single contiguous buffer (not even a gap) were very common and no one complained about their speed. Indeed, the benchmarks in this article confirm that.
As another popular article that's often submitted here says: computers are fast --- very fast for human timescales, and in particular manipulating text of humanly-encountered sizes. More performance is lost in unnecessary abstraction and belief that "clever" optimisations (like theoretically-optimal but considerably more complex data structures) work, when they actually turn out the opposite.
There's a lot of dogma around advanced text editor structures and what is "optimal", and IMHO a lot of that is totally unneeded accidental complexity created by those more interested in theoretical daydreaming than real-world solutions. Thus, I think even a gap buffer is "overkill", and a single "gapless" buffer is really sufficient. Don't overthink things.
- hoseja 3y agoAnd yet, search-and-replace on big files takes seconds.
- kaba0 3y agoI can grep through half my file system in seconds. What do you measure?
- PH95VuimJjqBqy 3y agoI don't know this authoritatively, but I believe vim uses a simple array internally. And it works well.