From edc52db15b240ea61a3bffdb7bf78a8be6aacf88 Mon Sep 17 00:00:00 2001 From: wangfukang Date: Sat, 9 Sep 2023 23:24:14 +0800 Subject: [PATCH] perf(rrweb): optimize random shuffled addList --- packages/rrweb/src/record/mutation.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 525a1af46b..4a2436c262 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -717,7 +717,13 @@ export default class MutationBuffer { 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.addedSet.has(n)) { + // update the order of added nodes in addedSet for the `emit` phase + this.addedSet.delete(n); + this.addedSet.add(n); + return; + } + if (this.movedSet.has(n)) return; if (this.mirror.hasNode(n)) { if (isIgnored(n, this.mirror)) {