Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Make LanguageMode::unfoldAll faster - #9468

Merged
as-cii merged 2 commits into
masterfrom
as-faster-unfold-all
Nov 6, 2015
Merged

as-cii merged 2 commits into
masterfrom
as-faster-unfold-all

Conversation

@as-cii

@as-cii as-cii commented Nov 6, 2015

Copy link
Copy Markdown
Contributor

All the benchmarks were performed by opening src/text-editor.coffee on startup.

In the previous implementation we were constantly querying TextBuffer for folds whenever the grammar on TextEditor changed:

screen shot 2015-11-06 at 14 29 22

Indeed, when changing the grammar we issue a call to LanguageMode::unfoldAll which tries to get a fold for each row in the buffer.

screen shot 2015-11-06 at 14 33 40

This happens also on startup because grammars are loaded after a TextEditor instance 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 of TextEditor as soon as the packages' grammars are loaded and a new grammar is recognized.

Solution

With this PR, instead of issuing a findMarker call to TextBuffer for 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:

screen shot 2015-11-06 at 13 22 04

Calling ::unfoldAll is almost instantaneous now and for a single ~3000 lines file this saves almost 150ms. 🐎 🐎 🐎

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

Comment thread src/display-buffer.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be named foldsIntersectingBufferRowRange, based on the query.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

@nathansobo

Copy link
Copy Markdown
Contributor

Having a little trouble following the flame graphs but the code changes are a no-brainer. Nice work. One naming-related comment, then 🚢.

as-cii added a commit that referenced this pull request Nov 6, 2015
Make LanguageMode::unfoldAll faster
@as-cii
as-cii merged commit 5647335 into master Nov 6, 2015
@as-cii
as-cii deleted the as-faster-unfold-all branch November 6, 2015 16:44
@as-cii

as-cii commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

❤️

@benogle benogle mentioned this pull request Nov 10, 2015
@tshort tshort mentioned this pull request Jan 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants