Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf($compile): only iterate over elements with link functions #8741

Closed
wants to merge 1 commit into from

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Aug 23, 2014

I've been thinking about this a while and @IgorMinar added a TODO for it in 3e0a2e1.

In a quick test I found this lowered the link time 5-10% for a table row with only ~2/15 cells requiring linking. For DOM trees with a higher percentage of annotated nodes this shouldn't have any noticeable effect. However I think having 50%+ non-annotated nodes is very common (a newline/whitespace text node per element...).

@IgorMinar
Copy link
Contributor

This is interesting! I'll review properly tomorrow

On Fri, Aug 22, 2014, 9:28 PM Jason Bedard notifications@github.com wrote:

I've been thinking about this a while and @IgorMinar
https://github.com/IgorMinar added a TODO for it in 3e0a2e1
3e0a2e1
.

In a quick test I found this lowered the link time 5-10% for a table row
with only ~2/15 cells requiring linking. For DOM trees with a higher
percentage of annotated nodes this shouldn't have any noticeable effect.
However I think having 50%+ non-annotated nodes is very common (a

newline/whitespace text node per element...).

You can merge this Pull Request by running

git pull https://github.com/jbedard/angular.js compile-linkfns

Or view, comment on, or merge it at:

#8741
Commit Summary

  • perf($compile): only iterate over elements with link functions

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#8741.

// create a sparse array by only copying the elements which have a linkFn
for (i = 0, ii = linkFns.length; i < ii; i+=3) {
idx = linkFns[i];
stableNodeList[idx] = nodeList[idx];
Copy link
Contributor

Choose a reason for hiding this comment

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

you are creating sparse arrays here. that will disable all major array optimizations in the VM. we need to avoid that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could just revert this block then. Or could the sparse array lookups be worth the shorter array and loop?

Or make stableNodeList non-sparse by just pushing the nodes onto it. Then we'd need another array mapping stableNodeList index => linkFn index? Sounds ugly...

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about this more and getting rid of the sparse array is not that easy as it makes code in the later loop more complicated. we should at least prealocate the array as we used to.

@IgorMinar IgorMinar added this to the 1.3.0-beta.20 milestone Aug 25, 2014
@IgorMinar IgorMinar self-assigned this Aug 25, 2014
@IgorMinar IgorMinar closed this in fdf9989 Aug 25, 2014
@IgorMinar
Copy link
Contributor

I went ahead and made the changes myself since I had your branch checked out already. I measured the impact and it's surprisingly small in the large table macro-benchmark. I think it will have bigger impact in the real world where the dom is more sparsely annotated though.

thanks for the PR!

@caitp
Copy link
Contributor

caitp commented Aug 25, 2014

@jbedard
Copy link
Contributor Author

jbedard commented Aug 25, 2014

That was fast. Thanks! Could this also be done merged into 1.2?

@IgorMinar
Copy link
Contributor

We need to cherry-pick a whole bunch of commits to 1.2 but I won't have
time this week so unless someone else syncs master and 1.2 branches it will
have to wait a bit

On Mon, Aug 25, 2014, 11:17 AM Jason Bedard notifications@github.com
wrote:

That was fast. Thanks! Could this also be done merged into 1.2?


Reply to this email directly or view it on GitHub
#8741 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants