3 ms·
This is very efficient, but the consequence is Vi will become slow when working with huge files, because it has to traverse through a bigger linear array To pu
by userbinator 9y ago
This is very efficient, but the consequence is Vi will become slow when working with huge files, because it has to traverse through a bigger linear array
To put "bigger" into perspective, a modern CPU can traverse and copy memory at over 10GB/s.
This is why I've always found the argument for more "efficient" (and complex) text editor data structures a bit tenuous --- even if you have to move MBs of data with every insertion (as happens with a simple gapless buffer), computers truly are so fast that it wouldn't look any different to the end-user; a 1ms and 1us delay upon each keystroke is, to the user, practically indistinguishable.
That's not to say I'm one of those who preach against "premature optimisation" and don't care about efficiency; far from that, in fact, but the popularity of and lack of speed-related complaints against the small DOS text editors and even syntax-highlighting IDEs on PCs in the 80s through early 90s which used the same "one buffer" paradigm, on machines with a fraction of the memory bandwidth of those today, suggest that the complexity of more "clever" data structures may not be worth it.
...and yet we somehow still manage to make editors that peg a single CPU core just blinking a cursor.[1]
[1] https://news.ycombinator.com/item?id=13940014 https://news.ycombinator.com/item?id=13940014
- kqr 9y ago> computers truly are so fast that it wouldn't look any different to the end-user; a 1ms and 1us delay upon each keystroke is, to the user, practically indistinguishable. Unless, of course, the 1 ms operation drains the users battery 1000x faster than the 1 us operation. Efficiency is no longer about speed, it's about noise, temperature, and battery life. Speed is a happy side effect.
- vidarh 9y agoI tend to agree with you. I'm using my own editor most of the time now. I occasionally fall back to Emacs still, but less and less. An early decision I made was to separate the buffers and almost all the rest of the editor code. It's slow Ruby. It's storing everything in an Array of String objects. Which means one (Ruby-internal) allocation per line for the String object, and an additional allocation for the rest of the String if it exceeds something like 24 characters (Ruby String objects store characters in the object itself if it's short enough, but otherwise store a pointer to a separate buffer). Every keypress (because I've been lazy and not bothered optimizing away cases where it's not needed), the frontend requests the full set of visible lines from the backend via a TCP connection (using Drb for RPC), and re-applies syntax highlighting and other formatting, and in the process causes a flurry of additional object allocations. It's not optimized at all. It's almost flagrantly wasteful in many areas. It started that way out of simplicity and a desire to get it to the point where I could use it for most of my editing ASAP. And it has remained that way so far because the lag just isn't noticeable to me, and it's very rare I edit large enough files for it to matter. I might optimize it at some point, but to me this seems like something people tend to worry too much about.
- gameswithgo 9y agosometimes efficiency can die due to a thousand cuts, and most text editors today end up running with plugins that also do compiling and highlighting and intellisense and so on. the work could add up, perhaps? also sometimes people work with really really big files for various reasons, good and bad.
- erikpukinskis 9y agoYou’re assuming the chipset is completely free and waiting to handle your text edits. If my editor is responsive while the computer is idle, but slows to a halt when I am running some other intensive process, that’s not good enough. I’d put the editor in the same category with the window manager and the terminal... the “needs to still work even while the machine is under extreme load for random reasons” category.