-
Notifications
You must be signed in to change notification settings - Fork 27.4k
perf($compile): only iterate over elements with link functions #8741
Conversation
406576a
to
2936d3e
Compare
This is interesting! I'll review properly tomorrow On Fri, Aug 22, 2014, 9:28 PM Jason Bedard notifications@github.com wrote:
|
// 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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
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! |
✨ |
That was fast. Thanks! Could this also be done merged into 1.2? |
We need to cherry-pick a whole bunch of commits to 1.2 but I won't have On Mon, Aug 25, 2014, 11:17 AM Jason Bedard notifications@github.com
|
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...).