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

[WIP] Packages performance improvements - #813

Closed
bastilian wants to merge 49 commits into
atom:masterfrom
bastilian:packages_performance_improvements
Closed

bastilian wants to merge 49 commits into
atom:masterfrom
bastilian:packages_performance_improvements

Conversation

@bastilian

@bastilian bastilian commented Jul 9, 2016 •

Copy link
Copy Markdown
Contributor

This a proposal to introduce a Package model, refactor PackageManager and address performance issues, make AtomIoClient obsolete and refactor components to use Package model and refactored PackageManager.

Introduce Package model

Currently PackageManager and PackageCard hold a number of functions that would be better in the context of a model. Things like installing, updating, uninstalling as well as checking various states of a package should be handled by the model and emit events that other components can rely on. It takes also responsibility to maintain it's avatar in the cache on disk. It will also listen to changes of it's cache item and emit an update event.

Refactor PackageManager

There is a lot of code that can be refactored. The result of the refactor will be unified promised command execution, consistent package information cache, return Package model instances instead of bare objects and, last but not least, expose command errors as notifications instead of swallowing them in console if it is caused by a user triggered action.

With moving to promised execution of apm commands we can reduce the confusion of multiple callbacks inter-mingling and make more clear what's going on. Execution of commands should also respect navigator.online and be prevented commands requiring network access from happening when offline.

PackageManager and AtomIoClient are caching package information in three different ways, as availablePackageCache, apmCache and localStorage. The latter should be the only place to cache. It will keep a cached JSON string for each package.

For installed, featured and outdated it will keep package-names in arrays. Installed package arrays will be split up by subkeys for core, user, dev and git, featured lists by subkeys for themes and packages.
The lists will be created when the cache is first initialised, updated asynchronously and emit events when they are changed, essentially moving in the List functionality or incorporating it. ListViews can listen for them and update appropriately, PackageManager will use them also to update package information cached.

Refactor components to use Package model and refactored PackageManager

PackageCard will be refactored to rely on the Package as well as the refactored PackageManager. The panels "Packages", "Themes", "Updates" and "Install" will also be affected by this, but only in regards to retrieving packages.

Main objective

The goal besides improving code and make it more readable, is to make the panels interacting with packages more responsive, by showing package lists and information when cached immediately and only update when changed by updates performed asynchronously.

Related issues

Todos

  • Implement promised based PackageManager#command
  • Implement localStorage cache in PackageManger
  • Implement PackageManager#getList with a list-key as an argument, returning an Object or Array with package names
  • Implement PackageManager#getListOfPackages calling #getList and map package names to Package instances

Note: I'll update related issues and todos over the course of the PR

@bastilian bastilian changed the title [WIP] Packages performance and improvements [WIP] Packages performance improvements Jul 9, 2016
@bastilian

Copy link
Copy Markdown
Contributor Author

I've started with refactoring of the PackageManager to use promises for interacting with apm and moved out the caching of outdated packages. Once all caching mechanisms are eliminated PackageManager will consistently cache package information and lists in localStorage.

I'll next refactor PackageCard and move more functionality into Package and make it the only Object that PackageCard acts on and listens to.

The specs have only changed in terms of execution, but not in expectations. In a few cases specs are simplified by moving expectations to the place it actually should be tested.

I've also started to add documentation and specs for functions old and new to make clearer what goes on and how things are expected to behave.

@bastilian

Copy link
Copy Markdown
Contributor Author

I'm almost done with a refactor and will push the changes as soon as i've adjusted the specs.
One thing I'm encountering over and over again is the following:

screen shot 2016-08-01 at 12 14 04

Anyone encountered this before and possibly know why it happens?

@winstliu

winstliu commented Aug 1, 2016

Copy link
Copy Markdown
Contributor

Anyone encountered this before and possibly know why it happens?

Yes, but no I have no idea why it happens and actually thought it was a Windows-only issue.

@bastilian

Copy link
Copy Markdown
Contributor Author

Just wanted to give you an update this PR.

Note: It has become a big one, in case you feel that it should be split up into separate ones let me know.

PackageManager is now completely refactored. All command execution runs through Promises and consistently returns Lists of Packages, which are kept in an Object cache and utilised in the views. It also caches package lists and package details in localStorage and keeps them up to date when a package is installed, updated or uninstalled and when the settings-view is activated (via consumeStatusBar). This can in the future also be used to keep package states up to date across Atom window instances. With that AtomIoClient has become obsolete and reduces the caches involved in this. Updates are now cached as well and do not need to be fetched again when the panel opens.

For caching avatars there is now a CachedAssets class providing a interface to manage them. PackageManager uses this and relays it via the asset function to Package used in PackageCard.

PackageCard is now cleaner and functionality said to be moved to a Package class are now implemented and used. Package is now responsible to relay updates to PackageCard, which was previously done through PackageManager.

I have added documentation to all new public functions as well as specs. I'll add more as I go on, so future contributors find there way around easier.

Currently a few specs fail, which I'll fix in the coming week. I also have a hunch on why PackageDetailView has a random failing spec and will try to fix it.

The functionality remains the same, you should see some minor improvements in performance. There are a few quirks still, which I'll iron out and have tests for them.

@bastilian

Copy link
Copy Markdown
Contributor Author

Since this has become a pretty huge refactor I have become more and more worried and uncomfortable to have it merged.
It is almost a complete rewrite and touches everything.
Therefore I think it is better to close this and maybe add the (concepts) of the improvements more gradually.

@bastilian bastilian closed this Oct 15, 2016
@damieng

damieng commented Oct 15, 2016 •

Copy link
Copy Markdown
Contributor

That's often the case with big refactorings :( Loop me in when you start each individual piece and I'll try and be your merge buddy.

@bastilian

Copy link
Copy Markdown
Contributor Author

@damieng yeah, I'll split them up into more logical changes and smaller packages and push them over time as PRs.

The refactoring itself was a piece of cake, but keeping up with maintaining the specs and keeping adjusting there setup stages was a hassle, since PackageManager is the heart of all and I ripped it out and stuck a new one in there.

Anyways. All of this did help me to get a detailed picture of literally all code and taking one bite at a time is going to be much easier. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants