When opening large log files (well, not that large, but 80mb is still a lot of text!), I've always used Vim since it loads them almost instantly. Other text editors like Notepad, Notepad++, etc will take > 10 seconds to process and load the file. What is the reason for this? What makes Vim so fast?
Answer
There's a multitude of tricks that editors can use to optimize dealing with large files.
One is to only work with what they need. That means not trying to parse the entire file for things like line counting, width measurements, word wrapping, syntax highlighting, XML validation, HTML rendering, Undo, etc. There is the LargeFile Plugin available for Vim which will disable a number of Vim's features when a "large" (as defined by the user) file is opened. The Faster loading of large files page on Vim's wiki mentions some of the disabled features: ignore filetype (for syntax highlighting/parsing), disable undo, switch to read-only mode. There's other changes too, but they seem to be targeted towards memory conservation than speed.
Another is memory mapping. Instead of reading the entire file into memory, tell the underlying OS to map a view of the file directly into the processes memory space. I'm not sure if Vim in particular does this, but other editors can and do.
Those are probably the biggest 2, but there's certainly more.
No comments:
Post a Comment