Skip to content

Addon._treeFor optimization#7634

Merged
rwjblue merged 1 commit intoember-cli:masterfrom
kellyselden:mergedTreesForType
Feb 25, 2018
Merged

Addon._treeFor optimization#7634
rwjblue merged 1 commit intoember-cli:masterfrom
kellyselden:mergedTreesForType

Conversation

@kellyselden
Copy link
Copy Markdown
Member

Without this, an empty array goes through mergeTrees and becomes a valid tree. With this change, it remains a falsy value and fails this check

if (val) { sum.push(val); }
meaning less trees to deal with.

This change is only a minor optimization now, but is more noticeable when paired with #7501.

Copy link
Copy Markdown
Contributor

@twokul twokul left a comment

Choose a reason for hiding this comment

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

I wonder if it makes sense to add this check within mergeTrees?

@kellyselden
Copy link
Copy Markdown
Member Author

That would probably break lots of code.

@kellyselden
Copy link
Copy Markdown
Member Author

Oh our internal mergeTrees helper. Sorry I misread. That might work.

@kellyselden
Copy link
Copy Markdown
Member Author

@rwjblue @stefanpenner Does it make sense that our internal mergeTrees helper might return null? or is that a concern best left to the caller and always return a tree?

annotation: `Addon#treeFor (${this.name} - ${treeType})`,
});
let mergedTreesForType;
if (trees.length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we be explicit ans use !== 0 here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

actually thinking about it, should we use the fastpath for length === 1 too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

our mergeTrees helper already has the length === 1 passthrough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated to !== 0

@twokul
Copy link
Copy Markdown
Contributor

twokul commented Feb 19, 2018

@kellyselden have you tried moving that check into internal mergeTrees function?

@kellyselden
Copy link
Copy Markdown
Member Author

Yes. A lot of code wasn't expecting it, so I would like to make sure it is the right direction from others before fixing up all the code and tests.

@stefanpenner
Copy link
Copy Markdown
Contributor

stefanpenner commented Feb 20, 2018

I think @rwjblue's utility aims to fix this: https://github.com/ember-cli/ember-cli/blob/master/lib/broccoli/merge-trees.js with the EmptyTree concept.

@kellyselden
Copy link
Copy Markdown
Member Author

@stefanpenner How so? That util always returns a tree, and in this case I want a falsy value.

@kellyselden
Copy link
Copy Markdown
Member Author

I could export function getEmptyTree and use that to compare against instead of a falsy check. Do you think that would be better @stefanpenner?

annotation: `Addon#treeFor (${this.name} - ${treeType})`,
});
let mergedTreesForType;
if (trees.length !== 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The custom merge trees that we use (lib/broccoli/merge-trees.js) should already be taking care of this, can you check into why it isn't?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But EMPTY_MERGE_TREE is truthy, is it not?


extensionsForType() {
return ['js'];
return ['template'];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems odd, why are the test changes required?

Copy link
Copy Markdown
Member Author

@kellyselden kellyselden Feb 21, 2018

Choose a reason for hiding this comment

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

because Addon.treeFor can now return a falsy value where it didn't before. mergeTrees helper always returns a truthy tree.

@kellyselden
Copy link
Copy Markdown
Member Author

@rwjblue updated with isEmptyTree like you suggested.

@rwjblue rwjblue merged commit 6601551 into ember-cli:master Feb 25, 2018
@kellyselden kellyselden deleted the mergedTreesForType branch February 25, 2018 13:34
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.

5 participants