Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

RFC for caching results of treeFor hook #90

Merged
merged 2 commits into from
Feb 2, 2017
Merged

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Dec 15, 2016

```
The default implementation for `Addon.prototype.cacheKeyForTree` will:

- Utilize a shared NPM package (e.g. `calculate-cache-key-for-tree`) that will generate a cache key that incorporates at least the following pieces of information:
Copy link
Contributor

Choose a reason for hiding this comment

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

An additional or complementary heuristic may be that they are at the exact same place on disk?

Copy link
Member Author

Choose a reason for hiding this comment

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

@stefanpenner - Ya, I'm happy to add that also.

Copy link
Contributor

@stefanpenner stefanpenner Dec 19, 2016

Choose a reason for hiding this comment

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

@rwjblue only if you think it adds value. Just wanted to share, in-case it was overlooked.

@trentmwillis trentmwillis changed the title RFC for caching results of treeFor hook results. RFC for caching results of treeFor hook Dec 16, 2016
homu added a commit to ember-cli/ember-cli that referenced this pull request Dec 16, 2016
Implement addon treeFor caching.

In Ember CLI today, all addons at each level are built through the standard `treeFor` / `treeFor*` hooks. These hooks are responsible for preprocessing the JavaScript included by the tree returned from that specific hook (e.g., `treeForAddon` preprocesses the JS for the addon tree). [This RFC](ember-cli/rfcs#90) proposes a mechanism that would allow these returned trees to be cached by default (when no build time customization is done) and expose proper hooks for addon authors to control the degree to which we dedupe these trees.

See [ember-cli/rfcs#90](ember-cli/rfcs#90) for more context.

*Note:* This effort was derived from @stefanpenner's work in #6429.

### TODO:

- [x] Unit test `cacheKeyForTree` implementation
  - [x] Confirm that `treeFor*` method overrides opt-out of caching
  - [x] Confirm that modifying `this.treeForMethods` opts out of caching.
  - [x] Confirm that repeated calls to `cacheKeyForTree` return the same value.
- [x] Unit test `treeFor` caching mechanism
- [x] Extract basic `cacheKeyForTree` implementation to stand alone utility function
   - [x] test

### Future TODO:

- [ ] Ensure `mergeTrees` macro utility function is updated to properly dedupe when called like `mergeTrees([treeA, treeA])`. (#6574)
- [ ] Updates to Broccoli to ensure that "reused / previously built trees" are represented properly in heimdall tree.  This will included confirming that `buildSteps` properly handles the deduplicated results and shows an improvement.
- [ ] Extract the default `cacheKeyForTree` implementation into a separate package.
- [ ] Add API docs for `Addon.prototype.cacheKeyForTree` (in a separate PR after the corresponding RFC lands, so that ember-cli.com/api does not show the experimental API's until the RFC lands).
Copy link
Contributor

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@trentmwillis trentmwillis left a comment

Choose a reason for hiding this comment

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

Looks good to me. Only potential suggestion would be mentioning the cache API and maybe link to cache-key-for-tree.

@kellyselden
Copy link
Member

This was promoted to Final Comment Period in our team meeting.

trentmwillis pushed a commit to trentmwillis/ember-cli that referenced this pull request Feb 1, 2017
@rwjblue
Copy link
Member Author

rwjblue commented Feb 2, 2017

Discussed at ember-cli core team meeting today. No new information was brought up during the final comment period, and all of the ember-cli core team is in favor.

Merging...

@rwjblue rwjblue merged commit c4e1869 into master Feb 2, 2017
@rwjblue rwjblue deleted the addon-tree-caching branch February 2, 2017 21:55
homu added a commit to ember-cli/ember-cli that referenced this pull request Feb 2, 2017
Promote cacheKeyForTree to public API

As discussed in ember-cli/rfcs#90. Should be good to go once the RFC is merged.

Pro tip: use `?w=1` when viewing the changes to tidy up the large amount of whitespace changes in the tests.
rwjblue added a commit to rwjblue/data that referenced this pull request Aug 1, 2017
This hook was added in [ember-cli/rfcs#90](https://github.com/ember-cli/rfcs/blob/master/complete/0090-addon-tree-caching.md),
and essentially guarantees that a given tree returned by an addon is
considered stable (or not).

In the case of Ember Data, we do not have different tree output
based on our parent (project or addon).

Specifically, this implementation allows both an app _and_ a lazy engine to
depend on `ember-data` without duplicating the `ember-data` assets in both
the `assets/vendor.js` and `engine-dist/<engine-name>/assets/engine-vendor.js`.
rwjblue added a commit to rwjblue/data that referenced this pull request Aug 10, 2017
This hook was added in [ember-cli/rfcs#90](https://github.com/ember-cli/rfcs/blob/master/complete/0090-addon-tree-caching.md),
and essentially guarantees that a given tree returned by an addon is
considered stable (or not).

In the case of Ember Data, we do not have different tree output
based on our parent (project or addon).

Specifically, this implementation allows both an app _and_ a lazy engine to
depend on `ember-data` without duplicating the `ember-data` assets in both
the `assets/vendor.js` and `engine-dist/<engine-name>/assets/engine-vendor.js`.
kategengler pushed a commit to kategengler/rfcs that referenced this pull request Jan 19, 2019
RFC for caching results of `treeFor` hook
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.

6 participants