Repository navigation
Make LanguageMode::unfoldAll faster - #9468
Conversation
There was a problem hiding this comment.
I think this should be named foldsIntersectingBufferRowRange, based on the query.
There was a problem hiding this comment.
Yeah, I thought to this as well but this seems inconsistent with the method below (::foldsContainingBufferRow) which performs a similar query. What do you think?
There was a problem hiding this comment.
Makes sense, but in that case, if a fold intersects a single row it also contains it. In this case it's a range of rows, and we know these folds don't fully contain the range, otherwise there would only be one big fold. I'd be down renaming the other method for clarity/consistent if it isn't being used by packages (it's private but still might as well avoid breakages just in case).
There was a problem hiding this comment.
A cursory search showed up that there's some reference to foldsContainingBufferRow in packages (some typescript header files), so I think it's just better to rename the new one only (7d97241).
Thanks! ✨
|
Having a little trouble following the flame graphs but the code changes are a no-brainer. Nice work. One naming-related comment, then 🚢. |
Make LanguageMode::unfoldAll faster
|
❤️ |
All the benchmarks were performed by opening
src/text-editor.coffeeon startup.In the previous implementation we were constantly querying
TextBufferfor folds whenever the grammar onTextEditorchanged:Indeed, when changing the grammar we issue a call to
LanguageMode::unfoldAllwhich tries to get a fold for each row in the buffer.This happens also on startup because grammars are loaded after a
TextEditorinstance gets created. Moreover, user's perceived responsiveness gets worse as more files (or larger files) need to be opened/restored because we change the grammar for every instance ofTextEditoras soon as the packages' grammars are loaded and a new grammar is recognized.Solution
With this PR, instead of issuing a
findMarkercall toTextBufferfor each buffer row, we just get all the folds intersecting the whole buffer and destroy them in reverse order. This is how the first graph looks like after the improvements:Calling
::unfoldAllis almost instantaneous now and for a single ~3000 lines file this saves almost150ms. 🐎 🐎 🐎In the same code path there's still some work we could do to make loading settings faster, as it would seem like we spend a considerable amount of time in just setting keys/values in
Config(at least during startup). Nevertheless, this should result in a significant responsiveness increase when users boot up Atom with some open files./cc: @nathansobo @atom/feedback