Skip to content

Commit

Permalink
perf: record processMutation (rrweb-io#1214)
Browse files Browse the repository at this point in the history
* perf: record processMutation

* Create mean-tips-impress.md

* Apply formatting changes
  • Loading branch information
wfk007 authored and eoghanmurray committed Jul 27, 2023
1 parent cc326a1 commit 33b8e5b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-tips-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

perf: optimize the performance of record in processMutation phase
3 changes: 3 additions & 0 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ export default class MutationBuffer {
// this node was already recorded in other buffer, ignore it
if (this.processedNodeManager.inOtherBuffer(n, this)) return;

// if n is added to set, there is no need to travel it and its' children again
if (this.addedSet.has(n) || this.movedSet.has(n)) return;

if (this.mirror.hasNode(n)) {
if (isIgnored(n, this.mirror)) {
return;
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 @@ -30,6 +30,12 @@ const suites: Array<
eval: 'window.workload()',
times: 10,
},
{
title: 'create 1000 DOM nodes and append into its previous looped node',
html: 'benchmark-dom-mutation-multiple-descendant-add.html',
eval: 'window.workload()',
times: 5,
},
];

function avg(v: number[]): number {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<body></body>
<script>
function addMultiNodes() {
const total = 1000;
let parent = document.body;
for (let i = 0; i < total; i++) {
const el = document.createElement('div');
el.textContent = `el-${i + 1}`;
parent.append(el);
parent = el;
}
}
window.workload = () => {
addMultiNodes();
};
</script>
</html>

0 comments on commit 33b8e5b

Please sign in to comment.