Demo page with async dom and webworkers
console.time('commonAppend');
for (let i = 0; i < 10000; i++) {
document.body.appendChild(document.createElement('div'));
}
console.timeEnd('commonAppend');
//commonAppend: 62.622802734375ms - 300+ms (depend at layout calculation time, t != const)
console.time('asyncAppend');
for (let i = 0; i < 10000; i++) {
let id = i;
asyncSendMessage({
action: 'createNode',
id: id,
tag: 'div'
});
asyncSendMessage({
action: 'bodyAppendChild',
id: id
});
}
console.timeEnd('asyncAppend');
//asyncAppend: 277.938232421875ms (not depend at layout calculation time, t = const)
console.time('asyncAppendGroup');
for (let i = 0; i < 10000; i++) {
let id = i;
asyncSendMessage([{
action: 'createNode',
id: id,
tag: 'div'
},{
action: 'bodyAppendChild',
id: id
}]);
}
console.timeEnd('asyncAppendGroup');
//asyncAppend: 117.579833984375ms (not depend at layout calculation time, t = const)
console.time('asyncAppendBatch');
var msgs = [];
for (let i = 0; i < 10000; i++) {
let id = i;
msgs.push({
action: 'createNode',
id: id,
tag: 'div'
});
msgs.push({
action: 'bodyAppendChild',
id: id
});
}
asyncSendMessage(msgs);
console.timeEnd('asyncAppendBatch');
//asyncAppend: 23.794189453125ms (not depend at layout calculation time, t = const)
requestAnimationFrame
we create fittable modifications list (pool slice)This is a proof of concept of asynchronous DOM modification example with:
Business logic
All DOM modifications came from WebWorker and applyed to Main thread DOM
async PreventDefault/StopPropagation - as part of concept