This project aims to create the DOM serialization function that has the smallest possible impact on the browser and the serialized page.
For every implementation version, we run the function 1 000 000 (one million) times in each browser engine.
The data presented summarizes the time needed to serialize a DOM tree with 1000 elements, 100 times. That's the way of catching subtle differences between different implementations in browsers with reduced timer accuracy (1 run may take less than 1 ms). The test is repeated for 100 different trees, 100 times for each tree, to get repeatable results.
Sole node traversal takes time. Even when we don't save anything in any way, but just visit all nodes and read their attributes, we block the thread for some time.
┌──────────┬──────┬──────┬──────┐
│ (index) │ p50 │ p95 │ p99 │
├──────────┼──────┼──────┼──────┤
│ firefox │ 45 │ 46 │ 49 │
│ chromium │ 29.2 │ 30.5 │ 33 │
│ webkit │ 14 │ 15 │ 16.5 │
└──────────┴──────┴──────┴──────┘
The direct strict creation approach gives these results for 100 iterations.
┌──────────┬──────┬──────┬──────┐
│ (index) │ p50 │ p95 │ p99 │
├──────────┼──────┼──────┼──────┤
│ firefox │ 71 │ 74 │ 78 │
│ chromium │ 49.1 │ 51.7 │ 58.3 │
│ webkit │ 22 │ 23 │ 26 │
└──────────┴──────┴──────┴──────┘