Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/kind-kids-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb": patch
---

Optimize performance of isParentRemoved by converting it to an iterative procedure
2 changes: 1 addition & 1 deletion .changeset/silent-plants-perform.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'rrweb': patch
"rrweb": patch
---

Return early for child same origin frames
16 changes: 8 additions & 8 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,15 @@ function _isParentRemoved(
n: Node,
mirror: Mirror,
): boolean {
const { parentNode } = n;
if (!parentNode) {
return false;
}
const parentId = mirror.getId(parentNode);
if (removes.some((r) => r.id === parentId)) {
return true;
let node: ParentNode | null = n.parentNode;
while (node) {
const parentId = mirror.getId(node);
if (removes.some((r) => r.id === parentId)) {
return true;
}
node = node.parentNode;
}
return _isParentRemoved(removes, parentNode, mirror);
return false;
}

function isAncestorInSet(set: Set<Node>, n: Node): boolean {
Expand Down
6 changes: 6 additions & 0 deletions packages/rrweb/test/benchmark/dom-mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const suites: Array<
// eval: 'document.querySelector("button").click()',
// times: 10,
// },
{
title: 'create 1000x 1 DOM nodes with deeply nested children',
html: 'benchmark-dom-mutation-deep-nested.html',
eval: 'window.workload()',
times: 10,
},
{
title: 'create 1000x10 DOM nodes',
html: 'benchmark-dom-mutation.html',
Expand Down
31 changes: 31 additions & 0 deletions packages/rrweb/test/html/benchmark-dom-mutation-deep-nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<body></body>
<script>
function init() {
const count = 100;

let roots = [];
for (let i = 0; i < count; ++i) {
const div = document.createElement('div');
document.body.appendChild(div);
roots.push(div);
}

let tree_depth = 256;
let children = [...roots];
while (tree_depth > 0) {
for (let i = 0; i < children.length; i++) {
const div = document.createElement('div');
children[i].appendChild(div);
children[i] = div;
}
tree_depth--;
}
}

window.workload = () => {
document.body.innerHTML = '';
init();
};
</script>
</html>