Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Don't build soft-wrapped line segments until they become visible on screen #312
Previously, when we encountered a buffer line that needed to soft wrap, we would intentionally construct and cache all screen lines for that buffer line, even if many of these screen lines weren't visible on screen. This made the code slightly simpler, because we never needed to resume construction of soft-wrapped line segments in the middle of a partially-cached line.
Unfortunately, this led to very bad performance when opening files with a single very long line, as reported in atom/atom#14952. We would end up constructing all screen lines for the entire file rather than just constructing the lines that were visible on screen.
In this PR, we remove the logic that forced us to build all segments of a soft-wrapped line. Instead, we introduce logic to allow construction of screen lines to resume in the middle of a soft wrap. There are two major pieces to this:
After 20k trials of our randomized test, I'm not seeing any incorrect behavior. Performance when loading a large file is also markedly improved. Here's an example of loading a user-submitted 4.5MB file containing a single line of JSON.
We block the main thread for 8.5 seconds while we pre-cache every screen line.
We build the screen lines in 113ms. Still longer than I would like, but not a disaster.
Raw speed is still important, and we're still too slow. If you move your cursor straight to the end of the file, the process will still block the main thread as we compute all the soft wrapped lines. I'm not sure how much room for optimization there is in the raw line construction code path. Perhaps we can do more to compute what we need for soft wraps and avoid constructing lines that are above the viewport as well. But this PR is a good start.