Skip to content

Commit 3bb90fd

Browse files
v6b: Batch adding to container => 80K balls
In version 6 (or 6a), we show balls by attaching them to container node one by one, might results in continuous forced reflow (if CSS is more complex). In version 6b, we use a temporary DocumentFragment node to store those balls, then add them to container all at once. The result is not much better. So we need to find another way to improve version 6.
1 parent e2284fd commit 3bb90fd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,21 @@
231231
for (var m = 0; m < MOVERS_COUNT; m++) {
232232
if (isInViewport(tops[m], scrollY)) {
233233
movers[m].style.left = topToLeft(tops[m], timestamp) + 'px';
234-
if (isHidden(m)) showImmediately(m);
235-
} else if (m != MOVERS_COUNT - 1) { // never hide the last mover to keep page size{
234+
// if (isHidden(m)) showImmediately(m); // 6a
235+
if (isHidden(m)) requestShow(m); // 6b
236+
} else if (m != MOVERS_COUNT - 1) { // never hide the last mover to keep page size
236237
if (isVisible(m)) hide(m);
237238
}
238239
}
240+
processShowRequests(); // 6b
239241

240242
if (window.running) rAF(updateFunc);
241243
// FIX: Not every balls need to check 'isInViewport'
242244
}
243245
//----------------------------------------------------------------------------------------------
244246
function showImmediately (m) { container.appendChild(movers[m]); }
247+
function requestShow (m) { batchNodeShow.appendChild(movers[m]); }
248+
function processShowRequests () { container.appendChild(batchNodeShow); }
245249
function hide (m) { hidden.appendChild(movers[m]); }
246250
function isHidden (m) { return movers[m].parentNode == hidden; }
247251
function isVisible (m) { return movers[m].parentNode == container; }

0 commit comments

Comments
 (0)