4 ms·
I dont see any problem with an array. Make it huge so you only have to reallocate every megabyte or so. Keep track of the document length and only move as much
by phkahler 7y ago
I dont see any problem with an array. Make it huge so you only have to reallocate every megabyte or so. Keep track of the document length and only move as much as needed. Your processor can do this every character faster than you can type. No need for fancy data structures, and trivial to load and save files. The interesting part then becomes formatting for the display.
- deleted 7y ago[deleted]
- jstimpfle 7y agoTry a 100MB file.
- clarry 7y agoTakes less than 100 ms to read in the file (calling realloc in a loop), insert a byte in the middle (realloc + memmove), and write the modified file out on stdout. The byte insertion amounts to about 4ms. That's hardly fast, yet still a lot snappier than most modern editors' UI or the web, where apparently achieving 60 fps for a few hundred dynamic DOM nodes is some kind of an achievement. https://gist.github.com/hmkemppainen/376b973c568fc122e2d8c843b49e8d0d https://gist.github.com/hmkemppainen/376b973c568fc122e2d8c84... This approach really starts to suck when you implement macros that are going to perform a lot of one-char inserts quickly. Or when you're editing multi-gigabyte files.
- jstimpfle 7y agoI must admit I was surprised, although I shouldn't be. Are we at > 10GB/s memory bandwidth now? > This approach really starts to suck when you implement macros that are going to perform a lot of one-char inserts quickly. Or when you're editing multi-gigabyte files. I'm working on an editor that I've optimized for such cases. In a test it made random edits to a 4GB file in < 50 microseconds. But, it cost a load of sweat and blood to get that rope data structure right. And it loads files only at about 100MB/s (should optimize for bulk inserts). https://github.com/jstimpfle/astedit https://github.com/jstimpfle/astedit
- userbinator 7y agoAre we at > 10GB/s memory bandwidth now? It's been around a decade since that line was crossed. The peak bandwidth of DDR3-1333 is just a bit over 10GB/s.
- cerberusss 7y agoInteresting project. You don't say so specifically, but it looks like it should compile on both Windows and Linux?
- jstimpfle 7y agoYes, I make it to compile on both platforms from time to time. The current commit should compile using MSVC, gcc, and clang I believe. I'm happy to fix any issues if you find them :-)
- phkahler 7y ago>> This approach really starts to suck when you implement macros that are going to perform a lot of one-char inserts quickly. What operation is that? Search and replace might have that effect but could be done by copying the entire buffer with replacement happening along the way.
- Laakeri 7y agoImagine inserting text in the middle of 1GB file. Moving 500MB of data will definitely take longer than 18ms, and thus will cause at least some visible lag.
- Dylan16807 7y agoThis is an editor for textual documents. Where did you get a 1GB file?
- Laakeri 7y agoFor example a server log file?
- Dylan16807 7y agoNot a document and why are you editing it?
- anthk 7y agoThis. The former should be using awk/perl on that and just operating on the chunks he found, never at the whole file at once. But, OFC, these new "programmers" can't even figure basic Unix tools. Or performance.