-
-
Notifications
You must be signed in to change notification settings - Fork 95
Slow Activation Time #330
Comments
We've done what we can to try and reduce startup time by lazy-loading as much as possible. There's going to be some overhead though because we do register a status tile in the lower left that lets you disable/enable format-on-save. If you or anyone else have any ideas on how to further reduce startup time, I'm happy to give it a shot. I also want to try implementing https://github.com/sindresorhus/import-lazy this instead of our own solution. |
Given that context I explored around a bit. As a caveat, I've never worked with Atom plugins so please forgive any naive assumptions I may make 😅 .
Looking at const getAllScopes = () => [
...getJavascriptScopes(),
...getTypescriptScopes(),
...getCssScopes(),
...getJsonScopes(),
...getGraphQlScopes(),
...getMarkdownScopes(),
]; It looks like babel handles the spread operator by loading all kinds of ES6 polyfills which is very time consuming for this one usage. Removing the spread syntax might stop that import and give savings. So those are some ideas :). Any context I'm missing that might make these futile? #2 might make #3 irrelevant. |
Next thing causing long load times -
Inlining those helper functions gives significant savings. Got the activation time down to 55ms 🎉 Inlining was my hack way of getting those functions out, so I'll see if I can rework things in a more elegant way... |
Remove need for ES6 array polyfills and only import lodash once required re prettier#330
@haroldtreen This is awesome. Maybe we can try |
Could do. I've actually opened a PR that solves the
Still haven't looked at lazy loading the tile callback, so maybe could trim this down more. But I can live with a 55ms activation time 😊 . |
Remove need for ES6 array polyfills and only import lodash once required re prettier#330
Remove need for ES6 array polyfills and only import lodash once required re prettier#330
Been digging around a tiny bit more. Some thoughts:
Overall, I've shaved another 15ms off the activation time with these techniques: But maybe there's race conditions that this would introduce. I'm not super familiar with atom best practices... Maybe also scratching the bottom of the barrel 😅 . |
Looks like other packages use https://github.com/AtomLinter/linter-eslint/blob/master/src/main.js#L53-L60 |
I've been trying to blog about these random open source patches. Show libraries I like. Show how welcoming they are to contributions. Show open source isn't scary. So my last one was about this fix: https://haroldtreen.com/tech/open-source/contributing-to/2018/01/15/contributing-to-prettier-atom/ Thanks again for the awesome project! |
@haroldtreen I read your blog post, was super cool! I think all of these ideas sound cool:
|
I'm going to close this for now because I think our objectives have been accomplished and activation time has been significantly reduced. |
@haroldtreen thanks for reporting the regression! I wonder what the proper fix should be? It might be the case that Atom supports this stuff without a polyfill, but I'd have to check that. I wonder if we could get away with just totally stopping using the Babel precompilation step entirely and we'd avoid these types of problems. |
While looking at the Maybe the best thing to do would remove the The real solution to the above issue will require removing the async/awaits. |
Oh, duh! Good point!
Another good point, I think you're right. I will try this out now in a new PR. |
Ok done! ^ |
Oh my gosh, I wish there was some way to lock this down in some kind of automated performance test or something, but I don't think there's an easy way to do that. I'm reopening for now. |
Looking at the diff I suspect...
|
Okay I guess that means I can just go into those new modules and explicitly require or avoid using all of lodash/fp |
Yes, but just for the files that are requested at activation time, what haroldteen refers to as the "critical path" (most of the code base is only
I do think that was the culprit last time, so I'd expect to see at least some performance gain from that, yes. |
You could also use something like Rollup to turn the package into a single file with minimal I/O. |
That's definitely a possibility, but I'm worried that may actually have the opposite effect. Right now, Atom is lazy-loading most of our codebase so we're avoiding a lot of code being on the critical path of Atom's startup routine. If we put the entire codebase into a single file, we may end up increasing the load time, unless I'm miscalculating? |
@robwise You could use code splitting to split the code into what has to be run at startup and what is dynamically loaded later. |
Current Behavior
prettier-atom
is showing up as my slowest package, with an activation time nearly 2x as long as the subsequent package.Expected Behavior
I would expect
prettier-atom
to boot closer to 100 ms? It seems to be an outlier, and I would like to understand why.Debug Info
OS: MacOS 10.13.2
I also experimented with
atom --profile-startup .
I've attached that profile:
CPU-20171228T150504.cpuprofile.zip
The text was updated successfully, but these errors were encountered: