Repository navigation
Load large files with fewer features but much better performance - #7130
Conversation
* Don’t tokenize * Don’t build metadata to support folds and soft wraps Remaining issues: * Max line length is hard coded * Foldable indicators should be disabled * Folding via API should be disallowed
This is pretty hacky. If we want to compute the true longest line, we’ll need to process every line, which is what large file mode is designed to avoid. So now whenever the display buffer returns a line, it has the potential to update the longest line. This is a bit weird because retrieving a line now has a side effect. It’s even more weird because the longest line will actually be wrong for the initial state updates in the TextEditorPresenter. But as soon as the user interacts in any way the dimensions are recomputed, so it works for now. A better approach may be to set a visible region on the display buffer. But I’d like to keep this low-touch until we have a chance to revisit the design of DisplayBuffer in a bigger way.
|
Awesome! I am a bit concerned about the experience for users though – I suspect that without some kind of extra feedback, loading a large file only to find that it has no syntax highlighting and no soft wrap support would still feel "broken". For those looking at plain text log files it wouldn't matter, but for those who are looking at files that would normally be associated with a grammar, I think it would be quite noticeable. What do you think? |
|
@mnquintana Yeah, it's not ideal. I'm not sure popping up a notification to apologize makes it any better though. And not loading the file at all is even worse. So considering this is something we could conceivably ship next week and that there's probably no way to support the full featureset in time for 1.0, I still think it's the right way to go. After all, I've seen people disable syntax highlighting in vim when working with big files. |
|
Interesting solution. I like it. 👍 |
|
So much improvement. So little code. 🚢 |
Load large files with fewer features but much better performance
|
I'd still vote for a "loading" progress bar. It's not really clear from the gif if Atom is just freezing trying to open to file or is it actually doing something, so imho a progress bar-like (or even a spinning dent) would be better than not showing anything. |
|
Yeah, a progress bar would be nice. |
|
This is just the improvement I could achieve quickly. The pause you see is a blocking computation that would freeze the progress bar anyway. It could be broken into 10ms chunks but that complicates things and still impacts responsiveness. It could be backgrounded but the majority of time is spent populating a reference-heavy data structure that I want to replace and would be awkward to serialize. I think we should revisit the progress bar after switching to a simpler line indexing structure and seeing what we can gain in linear performance first. I want a progress bar too, but I don't want to waste time serializing a data structure I want to replace. |
|
Okay, after thinking about this for a bit I think I will try to yield to the UI thread when building the line index so we can display a progress bar. True background computation in another process will have to wait for a new data structure, but it may be possible to give some feedback (with reduced responsiveness) before them. |
Pictured below is Atom opening an 18.5 MB file (repeated copies of jQuery):
Less Is More
The lion's share of overhead when working with text files goes to supporting the following features:
As files get larger, this overhead becomes more problematic. Yes, we can reduce this overhead and plan to do so, but it's also true that these features are less likely to be critical when editing really huge files. So this PR disables them for files above 2MB.
In return we can do the following:
TokenizedLines on demand instead of up-front. This skips all of the processing I was trying to perform in the background on Load large files in background #7060, which can now be closed. It also avoids the memory hit of storing horizontal spatial metadata for any lines we haven't yet viewed. I'm leaving lines cached once we compute them once to avoid creating the same line over and over again. We could potentially use an LRU ("least recently used") cache eviction strategy if we want to cap consumed memory, but I'm not sure it's worth prioritizing.TokenizedBufferfromDisplayBufferrather than storing a second copy of lines, since there are no folds and soft wraps. This isn't a huge win but it does avoid an extra potentially huge array of references.Metrics
Now that we've cleared a huge bottleneck, new bottlenecks are revealing themselves in the initial load of a large file. At least on an SSD, I/O really isn't high on the list yet. Here's a flame graph for loading that 18.5 MB file:
There's plenty of low hanging 🍎 in here. I've highlighted a few things that stood out to me.
@maxbrunsfeld:
TextBuffermight be a good first candidate forPatchafter all, at least in terms of getting that data structure optimized for insertion.SpanSkipListinsertion is by far the biggest remaining cost.From a memory perspective, the
SpanSkipListis also our biggest offender whenTokenizedLines are out of the way:Closing Thoughts
I still want to push the efficiency of the structures that support Atom's full feature set, and we have a bunch of ideas for how to do so. But in the meantime, this is a much better compromise than an error message.