As title. I just faced a situation that I have to browse some large file (for human, not machine perspective) with around 10,000~50,000 lines. Is it possible to only load those line that can be seen from the current window? E.g. Line 9542~9596, and add/release lines when scroll. I expect that this will increase the performance largely.
1 Answer
No. From the readfile
function in fileio.c:
/*
* We allocate as much space for the file as we can get, plus
* space for the old line plus room for one terminating NUL.
* The amount is limited by the fact that read() only can read
* up to max_unsigned characters (and other things).
*/
Doing a strace -o logfile vim -u NONE largefile
confirms that Vim will indeed entirely load the entire file by issuing as many read
calls as necessary (you will find them right after the first chmod
line).
...and add/release lines when scroll. I expect that this will increase the performance largely.
Not really. The only significant performance gain would be in the start up time, simply because initially only a window worth of lines would be read from disk into memory.
Assuming the file fits in memory (and yours is only a few MiB in size), once it is loaded, there is no performance penalty in keeping it there.
Sluggishness on large files may be caused by plugins, as you found out to be your case by running vim --noplugin largefile
-
Sad, I thought I remembered reading something about some kind of smart buffering. Obviously not.– D. Ben Knoble ♦Apr 27 at 15:12
less
rather than vimex
ored
, which are supposed to be quite performant also, and avoid the screen bits. Then you can, say,9542,9596print
to see a section of the file.