Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating extraneous merge-trees. #6453

Merged
merged 1 commit into from Nov 23, 2016
Merged

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Nov 22, 2016

This change does three main things:

  • Ensure that we always use lib/broccoli/merge-trees.js over requiring broccoli-merge-trees directly.
  • When lib/broccoli/merge-trees.js is called with a single input tree, simply return it (instead of creating a broccoli-merge-tree instance).
  • When mergeTrees is called with an empty array, use a single EMPTY_MERGE_TREES constant instance for all invocations. This prevents us from creating many useless operations to essentially support an "empty" tree. It is possible that we might want to teach Broccoli itself about empty trees, but that is left as a future excercise.

The results of these changes even in a newly created empty app are fairly significant. Here are the counts of tmp directories created before and after:

  • 952 - Before changes
  • 274 - After changes

In a real app, these numbers would be even higher (due to addons at each level of nesting).


Credit goes to @stefanpenner for the idea and initial implementation (which was stolen from #6429).

@stefanpenner
Copy link
Contributor

stefanpenner commented Nov 22, 2016

nice!

@rwjblue may complement this nicely broccolijs/broccoli-merge-trees#43 (collapsing merge of merge)

@rwjblue
Copy link
Member Author

rwjblue commented Nov 22, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Nov 22, 2016

📌 Commit 380c2ec has been approved by rwjblue

@homu
Copy link
Contributor

homu commented Nov 22, 2016

⌛ Testing commit 380c2ec with merge 95d4533...

homu added a commit that referenced this pull request Nov 22, 2016
Avoid creating extraneous merge-trees.

This change does three main things:

* Ensure that we always use `lib/broccoli/merge-trees.js` over requiring `broccoli-merge-trees` directly.
* When `lib/broccoli/merge-trees.js` is called with a single input tree, simply return it (instead of creating a `broccoli-merge-tree` instance).
* When `mergeTrees` is called with an empty array, use a single `EMPTY_MERGE_TREES` constant instance for all invocations.  This prevents us from creating many useless operations to essentially support an "empty" tree.  It is possible that we might want to teach Broccoli itself about empty trees, but that is left as a future excercise.

The results of these changes even in a newly created empty app are fairly significant. Here are the counts of `tmp` directories created before and after:

* 952 - Before changes
* 316 - After changes

In a real app, these numbers would be even higher (due to addons at each level of nesting).

---

Credit goes to @stefanpenner for the idea and initial implementation (which was stolen from #6429).
options.description = options.annotation;
var tree = upstreamMergeTrees(inputTree, options);
module.exports = function mergeTrees(_inputTrees, options) {
var inputTrees = _inputTrees.filter(Boolean);
Copy link
Contributor

Choose a reason for hiding this comment

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

we may also want to filter out other EmptyMergeTrees here.

options = options || {};
options.description = options.annotation;
var tree = upstreamMergeTrees(inputTree, options);
module.exports = function mergeTrees(_inputTrees, options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should likely test this guy.

@rwjblue
Copy link
Member Author

rwjblue commented Nov 22, 2016

@homu r-

@homu
Copy link
Contributor

homu commented Nov 22, 2016

☀️ Test successful - status

@rwjblue
Copy link
Member Author

rwjblue commented Nov 22, 2016

@stefanpenner - Updated with tests and better filtering when input array contains the EMPTY_MERGE_TREE constant (this reduced the number of tmp dirs further down to 274).

@rwjblue
Copy link
Member Author

rwjblue commented Nov 23, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Nov 23, 2016

📌 Commit 332c720 has been approved by rwjblue

@homu
Copy link
Contributor

homu commented Nov 23, 2016

⌛ Testing commit 332c720 with merge 5e8b19b...

homu added a commit that referenced this pull request Nov 23, 2016
Avoid creating extraneous merge-trees.

This change does three main things:

* Ensure that we always use `lib/broccoli/merge-trees.js` over requiring `broccoli-merge-trees` directly.
* When `lib/broccoli/merge-trees.js` is called with a single input tree, simply return it (instead of creating a `broccoli-merge-tree` instance).
* When `mergeTrees` is called with an empty array, use a single `EMPTY_MERGE_TREES` constant instance for all invocations.  This prevents us from creating many useless operations to essentially support an "empty" tree.  It is possible that we might want to teach Broccoli itself about empty trees, but that is left as a future excercise.

The results of these changes even in a newly created empty app are fairly significant. Here are the counts of `tmp` directories created before and after:

* 952 - Before changes
* 274 - After changes

In a real app, these numbers would be even higher (due to addons at each level of nesting).

---

Credit goes to @stefanpenner for the idea and initial implementation (which was stolen from #6429).
@homu
Copy link
Contributor

homu commented Nov 23, 2016

☀️ Test successful - status

@homu homu merged commit 332c720 into master Nov 23, 2016
@rwjblue rwjblue deleted the avoid-needless-merge-trees branch November 23, 2016 13:23
@rwjblue
Copy link
Member Author

rwjblue commented Nov 23, 2016

Tested this in Ghost, the tmp dirs created during ember s went from 3444 to 966.

@Turbo87 Turbo87 added this to the v2.11.0 milestone Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants