{"action":"created","issue":{"url":"https://api.github.com/repos/atom/atom/issues/9468","labels_url":"https://api.github.com/repos/atom/atom/issues/9468/labels{/name}","comments_url":"https://api.github.com/repos/atom/atom/issues/9468/comments","events_url":"https://api.github.com/repos/atom/atom/issues/9468/events","html_url":"https://github.com/atom/atom/pull/9468","id":115508527,"number":9468,"title":"Make LanguageMode::unfoldAll faster","user":{"login":"as-cii","id":482957,"avatar_url":"https://avatars.githubusercontent.com/u/482957?v=3","gravatar_id":"","url":"https://api.github.com/users/as-cii","html_url":"https://github.com/as-cii","followers_url":"https://api.github.com/users/as-cii/followers","following_url":"https://api.github.com/users/as-cii/following{/other_user}","gists_url":"https://api.github.com/users/as-cii/gists{/gist_id}","starred_url":"https://api.github.com/users/as-cii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/as-cii/subscriptions","organizations_url":"https://api.github.com/users/as-cii/orgs","repos_url":"https://api.github.com/users/as-cii/repos","events_url":"https://api.github.com/users/as-cii/events{/privacy}","received_events_url":"https://api.github.com/users/as-cii/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-06T13:50:54Z","updated_at":"2015-11-06T16:44:38Z","closed_at":"2015-11-06T16:44:33Z","pull_request":{"url":"https://api.github.com/repos/atom/atom/pulls/9468","html_url":"https://github.com/atom/atom/pull/9468","diff_url":"https://github.com/atom/atom/pull/9468.diff","patch_url":"https://github.com/atom/atom/pull/9468.patch"},"body":"_All the benchmarks were performed by opening `src/text-editor.coffee` on startup_.\r\n\r\nIn the previous implementation we were constantly querying `TextBuffer` for folds whenever the grammar on `TextEditor` changed:\r\n\r\n![screen shot 2015-11-06 at 14 29 22](https://cloud.githubusercontent.com/assets/482957/10998082/d9b7339c-8492-11e5-8f34-014d780743f2.png)\r\n\r\nIndeed, when changing the grammar we issue a call to `LanguageMode::unfoldAll` which tries to get a fold for each row in the buffer. \r\n\r\n![screen shot 2015-11-06 at 14 33 40](https://cloud.githubusercontent.com/assets/482957/10998152/6ad7aa82-8493-11e5-9ac7-6674ee1a53f1.png)\r\n\r\nThis 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.\r\n\r\n### Solution\r\n\r\nWith 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:\r\n\r\n![screen shot 2015-11-06 at 13 22 04](https://cloud.githubusercontent.com/assets/482957/10998210/d2316e20-8493-11e5-9458-9c58ab169d3c.png)\r\n\r\nCalling `::unfoldAll` is almost instantaneous now and for a single ~3000 lines file this saves almost `150ms`. :racehorse: :racehorse: :racehorse: \r\n\r\nIn 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.\r\n\r\n/cc: @nathansobo @atom/feedback "},"comment":{"url":"https://api.github.com/repos/atom/atom/issues/comments/154466897","html_url":"https://github.com/atom/atom/pull/9468#issuecomment-154466897","issue_url":"https://api.github.com/repos/atom/atom/issues/9468","id":154466897,"user":{"login":"as-cii","id":482957,"avatar_url":"https://avatars.githubusercontent.com/u/482957?v=3","gravatar_id":"","url":"https://api.github.com/users/as-cii","html_url":"https://github.com/as-cii","followers_url":"https://api.github.com/users/as-cii/followers","following_url":"https://api.github.com/users/as-cii/following{/other_user}","gists_url":"https://api.github.com/users/as-cii/gists{/gist_id}","starred_url":"https://api.github.com/users/as-cii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/as-cii/subscriptions","organizations_url":"https://api.github.com/users/as-cii/orgs","repos_url":"https://api.github.com/users/as-cii/repos","events_url":"https://api.github.com/users/as-cii/events{/privacy}","received_events_url":"https://api.github.com/users/as-cii/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T16:44:38Z","updated_at":"2015-11-06T16:44:38Z","body":":heart: "}}