Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Load snippets lazily - #182

Merged
as-cii merged 15 commits into
masterfrom
as-lazy-load
Nov 10, 2015
Merged

as-cii merged 15 commits into
masterfrom
as-lazy-load

Conversation

@as-cii

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

Copy link
Copy Markdown
Contributor

Our current situation on master looks like the following during startup:

screen shot 2015-11-05 at 15 46 51

Out of 3s, ~410ms are spent in loading snippets:

screen shot 2015-11-05 at 15 48 01

Although this doesn't synchronously affect Atom's initialization (i.e. window.onload), it has an heavy impact on user experience. Indeed, trying to disable the snippets package results in a more fluid and responsive startup.

The idea with this PR is to avoid doing all the work of parsing snippets upfront and to defer it to the last possible moment. In the past, other packages relied on atom.config.get to access loaded snippets: because of configuration being eager by design, we couldn't afford this anymore and we've provided a service instead for other packages to use in order to introduce laziness.

The bad news is that this will be a breaking change, whereas the good news is that snippets take ~30ms to be loaded, thus not getting in the way of other important tasks such as background tokenization, etc. Any ideas on how to handle this? I think that just ⬆️ bumping the major version could be fine here, because the only package I have found which currently uses snippets that way is autocomplete-snippets and I am going to update it shortly.

Also, please note that I ended up not implementing a cache mechanism for parsed snippets, as the amount of parsing we do now is quite minimal and it doesn't seem to affect responsiveness on each keystroke.

/cc: @nathansobo @maxbrunsfeld @atom/feedback

@nathansobo

Copy link
Copy Markdown
Contributor

Also, please note that I ended up not implementing a cache mechanism for parsed snippets, as the amount of parsing we do now is quite minimal and it doesn't seem to affect responsiveness on each keystroke.

How long do snippets take to parse? Paying this every time we expand one is a bit of a bummer, but if it's way below frame budget then it's fine.

@nathansobo

Copy link
Copy Markdown
Contributor

Code looks fine to me. So long as you're sure we aren't hosing any third party packages I'd say 🚢 once you have a backward-compatible update to the AC+ provider in place.

@as-cii

as-cii commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

How long do snippets take to parse? Paying this every time we expand one is a bit of a bummer, but if it's way below frame budget then it's fine.

The time spent in parsing snippets varies on the number of them, but I have measured it takes ~12-15ms to parse a bunch of them (n_snippets <= 10). This doesn't seem to impact the responsiveness, though, and that's why I didn't explore a caching solution. Coming back to this, however, I agree with you that not having it is somewhat a bummer, so before 🚢ping this I'll implement one.

Code looks fine to me. So long as you're sure we aren't hosing any third party packages I'd say once you have a backward-compatible update to the AC+ provider in place.

atom/autocomplete-snippets#60 should be good to go, as CI is 💚 after making the code backwards-compatible. No other packages is seemingly using atom.config.get('snippets') but I'll have another 👀 just to be 100% sure.

Thanks for the review, will ping you as soon as I make the changes.

@as-cii

as-cii commented Nov 9, 2015

Copy link
Copy Markdown
Contributor Author

Okay, so I had another look at which packages were using snippets through atom.config and I found out that settings-view was using some atom.config internal to access all the loaded snippets. I provided a safer alternative in 9967bfc and used it in atom/settings-view#694 in a backwards-compatible manner.

I've also implemented a simple caching mechanism which addresses the concerns brought up in #182 (comment).

I think this is ready to be 🚢ped but it would be great to have another pair of 👀 before doing so. Thanks! 🙏

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

✨ This all looks most excellent to me.

as-cii added a commit that referenced this pull request Nov 10, 2015
@as-cii
as-cii merged commit 904b145 into master Nov 10, 2015
@as-cii
as-cii deleted the as-lazy-load branch November 10, 2015 08:31
@as-cii

as-cii commented Nov 10, 2015

Copy link
Copy Markdown
Contributor Author

Published as v1.0.1, as theoretically this is a breaking change (publishing 1.0.0 gave an error, so I published a new version incrementing only the patch number).

@jeancroy

Copy link
Copy Markdown

If snippets continue to be a bottleneck there's probably room for improvement for the parsing per se.
Especially the claim that we cannot deal with \ style escape in emca regex is not quite true.

That being said regex isn't especially fast for anything so maybe it doesn't matter.

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.

4 participants