Skip to content

Commit 0435984

Browse files
committed
perf(mutation): add deep recursive test
1 parent 2e5c904 commit 0435984

File tree

3 files changed

+68
-27
lines changed

3 files changed

+68
-27
lines changed

packages/rrweb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"check-types": "tsc -noEmit",
2323
"prepublish": "npm run typings && npm run bundle",
2424
"lint": "yarn eslint src",
25-
"benchmark": "jest test/benchmark"
25+
"benchmark": "jest test/benchmark/dom-mutation"
2626
},
2727
"type": "module",
2828
"repository": {

packages/rrweb/test/benchmark/dom-mutation.test.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,41 @@ const suites: Array<
1919
// times: 10,
2020
// },
2121
{
22-
title: 'create 1000x10 DOM nodes',
23-
html: 'benchmark-dom-mutation.html',
24-
eval: 'window.workload()',
25-
times: 10,
26-
},
27-
{
28-
title: 'create 1000x10x2 DOM nodes and remove a bunch of them',
29-
html: 'benchmark-dom-mutation-add-and-remove.html',
30-
eval: 'window.workload()',
31-
times: 10,
32-
},
33-
{
34-
title: 'create 1000 DOM nodes and append into its previous looped node',
35-
html: 'benchmark-dom-mutation-multiple-descendant-add.html',
36-
eval: 'window.workload()',
37-
times: 5,
38-
},
39-
{
40-
title: 'create 10000 DOM nodes and move it to new container',
41-
html: 'benchmark-dom-mutation-add-and-move.html',
42-
eval: 'window.workload()',
43-
times: 5,
44-
},
45-
{
46-
title: 'modify attributes on 10000 DOM nodes',
47-
html: 'benchmark-dom-mutation-attributes.html',
22+
title: 'create 1000x 1 DOM nodes with deeply nested children',
23+
html: 'benchmark-dom-mutation-deep-nested.html',
4824
eval: 'window.workload()',
4925
times: 10,
5026
},
27+
// {
28+
// title: 'create 1000x10 DOM nodes',
29+
// html: 'benchmark-dom-mutation.html',
30+
// eval: 'window.workload()',
31+
// times: 10,
32+
// },
33+
// {
34+
// title: 'create 1000x10x2 DOM nodes and remove a bunch of them',
35+
// html: 'benchmark-dom-mutation-add-and-remove.html',
36+
// eval: 'window.workload()',
37+
// times: 10,
38+
// },
39+
// {
40+
// title: 'create 1000 DOM nodes and append into its previous looped node',
41+
// html: 'benchmark-dom-mutation-multiple-descendant-add.html',
42+
// eval: 'window.workload()',
43+
// times: 5,
44+
// },
45+
// {
46+
// title: 'create 10000 DOM nodes and move it to new container',
47+
// html: 'benchmark-dom-mutation-add-and-move.html',
48+
// eval: 'window.workload()',
49+
// times: 5,
50+
// },
51+
// {
52+
// title: 'modify attributes on 10000 DOM nodes',
53+
// html: 'benchmark-dom-mutation-attributes.html',
54+
// eval: 'window.workload()',
55+
// times: 10,
56+
// },
5157
];
5258

5359
function avg(v: number[]): number {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<html>
2+
<body></body>
3+
<script>
4+
function init() {
5+
const count = 1000;
6+
7+
let roots = [];
8+
for (let i = 0; i < count; ++i) {
9+
const div = document.createElement('div');
10+
document.body.appendChild(div);
11+
roots.push(div);
12+
}
13+
14+
let tree_depth = 64;
15+
let children = [...roots];
16+
while (tree_depth > 0) {
17+
for (let i = 0; i < children.length; i++) {
18+
const div = document.createElement('div');
19+
children[i].appendChild(div);
20+
children[i] = div;
21+
}
22+
tree_depth--;
23+
}
24+
}
25+
26+
init();
27+
28+
window.workload = () => {
29+
const divs = document.getElementsByTagName('div');
30+
for (let div of divs) {
31+
div.classList.add('foo');
32+
}
33+
};
34+
</script>
35+
</html>

0 commit comments

Comments
 (0)