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

[CLEANUP] Don't cache length property in for loops #12744

Closed
wants to merge 1 commit into from

Conversation

topaxi
Copy link
Contributor

@topaxi topaxi commented Dec 22, 2015

Just like in emberjs/data#4015

@topaxi
Copy link
Contributor Author

topaxi commented Dec 22, 2015

I'm not sure if the failed tests are due to this change or some weird IE9 behavior. It seems to timeout in two tests which seem unrelated to these changes.

@rwjblue
Copy link
Member

rwjblue commented Dec 22, 2015

I will try to review in more detail later tonight/tomorrow, but one thing I wanted to make sure you took into account was that sometimes caching the length is actually needed. Specifically, when you are in a loop and you are mutating that array inside the loop you may need to cache length (depending on what you are doing). Did you review the surrounding code to confirm that is not the case in these instances?

@@ -40,7 +40,7 @@ ChainWatchers.prototype = {
remove(key, node) {
let nodes = this.chains[key];
if (nodes) {
for (var i = 0, l = nodes.length; i < l; i++) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] === node) {
nodes.splice(i, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Self note: This loop length should probably be cached.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a second look, this shouldn't need to cache length as we break the loop on the next line, might be confusing though.

@topaxi
Copy link
Contributor Author

topaxi commented Dec 22, 2015

I did review surrounding code and it seemed that all those loops never mutated the iterated array / array-like object. Unless there are some liverecord-like arrays involved, there shouldn't be any issues.

I might missed one or two, currently double-checking the whole commit myself.

@homu
Copy link
Contributor

homu commented Jan 18, 2016

☔ The latest upstream changes (presumably #12831) made this pull request unmergeable. Please resolve the merge conflicts.

@topaxi topaxi force-pushed the dont-cache-length branch from b3bf9a0 to 7082e58 Compare January 18, 2016 13:17
@topaxi
Copy link
Contributor Author

topaxi commented Jan 18, 2016

Resolved merge conflicts and rebased on master.

@stefanpenner
Copy link
Member

Seems good, we will just need to double check each change.

@homu
Copy link
Contributor

homu commented Jan 30, 2016

☔ The latest upstream changes (presumably b8786ba) made this pull request unmergeable. Please resolve the merge conflicts.

@homu
Copy link
Contributor

homu commented Jan 30, 2016

☔ The latest upstream changes (presumably e07d3cf) made this pull request unmergeable. Please resolve the merge conflicts.

@topaxi topaxi force-pushed the dont-cache-length branch from 7082e58 to bc1edcf Compare February 3, 2016 10:33
@homu
Copy link
Contributor

homu commented Feb 9, 2016

☔ The latest upstream changes (presumably #12929) made this pull request unmergeable. Please resolve the merge conflicts.

@topaxi topaxi force-pushed the dont-cache-length branch from bc1edcf to c482419 Compare February 9, 2016 18:34
@homu
Copy link
Contributor

homu commented Feb 14, 2016

☔ The latest upstream changes (presumably #12928) made this pull request unmergeable. Please resolve the merge conflicts.

@homu
Copy link
Contributor

homu commented Mar 24, 2016

☔ The latest upstream changes (presumably b295edb) made this pull request unmergeable. Please resolve the merge conflicts.

@rwjblue
Copy link
Member

rwjblue commented Apr 10, 2016

Thank you for your time on this! I'm going to go ahead and close this for now as it seems to have gone stale. I'm happy to reopen if you would like to pick this back up again.

@rwjblue rwjblue closed this Apr 10, 2016
@topaxi
Copy link
Contributor Author

topaxi commented Apr 11, 2016

Rebased and pushed to the branch https://github.com/topaxi/ember.js/tree/dont-cache-length
Github does not seem to update this PR though, is this because the PR is now closed?

I'm happy to reopen a new PR and update or rebase this as needed, just ping me if new merge conflicts happen.

@rwjblue
Copy link
Member

rwjblue commented Apr 11, 2016

Weird, it won't let me reopen the PR (I was able to reopen at least one that I closed yesterday).

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.

4 participants