Skip to content

Improve VDOM's iteration performance #145

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/Elm/Kernel/VirtualDom.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ function _VirtualDom_render(vNode, eventNode)

_VirtualDom_applyFacts(domNode, eventNode, vNode.__facts);

for (var kids = vNode.__kids, i = 0; i < kids.length; i++)
var len = kids.length;
for (var kids = vNode.__kids, i = 0; len - i; i++)
{
_VirtualDom_appendChild(domNode, _VirtualDom_render(tag === __2_NODE ? kids[i] : kids[i].b, eventNode));
}
Expand Down Expand Up @@ -833,7 +834,8 @@ function _VirtualDom_diffHelp(x, y, patches, index)
// assumes the incoming arrays are the same length
function _VirtualDom_pairwiseRefEqual(as, bs)
{
for (var i = 0; i < as.length; i++)
var len = as.length;
for (var i = 0; len - i; i++)
{
if (as[i] !== bs[i])
{
Expand Down Expand Up @@ -964,7 +966,7 @@ function _VirtualDom_diffKids(xParent, yParent, patches, index)

// PAIRWISE DIFF EVERYTHING ELSE

for (var minLen = xLen < yLen ? xLen : yLen, i = 0; i < minLen; i++)
for (var minLen = xLen < yLen ? xLen : yLen, i = 0; minLen - i; i++)
{
var xKid = xKids[i];
_VirtualDom_diffHelp(xKid, yKids[i], patches, ++index);
Expand Down Expand Up @@ -994,7 +996,7 @@ function _VirtualDom_diffKeyedKids(xParent, yParent, patches, rootIndex)

var index = rootIndex;

while (xIndex < xLen && yIndex < yLen)
while ( xLen - xIndex && yLen - yIndex)
{
var x = xKids[xIndex];
var y = yKids[yIndex];
Expand Down Expand Up @@ -1108,7 +1110,7 @@ function _VirtualDom_diffKeyedKids(xParent, yParent, patches, rootIndex)

// eat up any remaining nodes with removeNode and insertNode

while (xIndex < xLen)
while (xLen - xIndex)
{
index++;
var x = xKids[xIndex];
Expand All @@ -1118,7 +1120,7 @@ function _VirtualDom_diffKeyedKids(xParent, yParent, patches, rootIndex)
xIndex++;
}

while (yIndex < yLen)
while (yLen - yIndex)
{
var endInserts = endInserts || [];
var y = yKids[yIndex];
Expand Down Expand Up @@ -1313,7 +1315,8 @@ function _VirtualDom_addDomNodesHelp(domNode, vNode, patches, i, low, high, even

var vKids = vNode.__kids;
var childNodes = domNode.childNodes;
for (var j = 0; j < vKids.length; j++)
var len = vKids.length;
for (var j = 0; len - j; j++)
{
low++;
var vKid = tag === __2_NODE ? vKids[j] : vKids[j].b;
Expand Down Expand Up @@ -1349,7 +1352,8 @@ function _VirtualDom_applyPatches(rootDomNode, oldVirtualNode, patches, eventNod

function _VirtualDom_applyPatchesHelp(rootDomNode, patches)
{
for (var i = 0; i < patches.length; i++)
var len = patches.length;
for (var i = 0; len - i; i++)
{
var patch = patches[i];
var localDomNode = patch.__domNode
Expand Down Expand Up @@ -1467,7 +1471,8 @@ function _VirtualDom_applyPatchReorder(domNode, patch)

// inserts
var inserts = data.__inserts;
for (var i = 0; i < inserts.length; i++)
var len = inserts.length;
for (var i = 0; len - i; i++)
{
var insert = inserts[i];
var entry = insert.__entry;
Expand Down Expand Up @@ -1495,7 +1500,8 @@ function _VirtualDom_applyPatchReorderEndInsertsHelp(endInserts, patch)
}

var frag = _VirtualDom_doc.createDocumentFragment();
for (var i = 0; i < endInserts.length; i++)
var len = endInserts.length;
for (var i = 0; len - i; i++)
{
var insert = endInserts[i];
var entry = insert.__entry;
Expand Down Expand Up @@ -1554,7 +1560,7 @@ function _VirtualDom_dekey(keyedNode)
var keyedKids = keyedNode.__kids;
var len = keyedKids.length;
var kids = new Array(len);
for (var i = 0; i < len; i++)
for (var i = 0; len - i; i++)
{
kids[i] = keyedKids[i].b;
}
Expand Down