From 4a984b0941e099c6de7ed557ea95238cd8c9e9c2 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Thu, 18 Jul 2024 14:50:59 -0400 Subject: [PATCH] use for loop --- packages/rrweb/src/record/mutation.ts | 18 ++++-------------- .../rrweb/src/record/processed-node-manager.ts | 5 +---- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 4d7e56e637..eea21502fc 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -690,12 +690,7 @@ export default class MutationBuffer { // iterate breadth first over new nodes (non recursive for performance) while (genAddsQueue.length) { - const next = genAddsQueue.pop()!; - - // Since this is an extremely hot path, do not destructure next - // in order to avoid invoking the iterator protocol - const n = next[0]; - const target = next[1]; + const [n, target] = genAddsQueue.pop()!; // this node was already recorded in other buffer, ignore it if (this.processedNodeManager.inOtherBuffer(n, this)) continue; @@ -728,17 +723,11 @@ export default class MutationBuffer { for (let j = n.childNodes.length - 1; j >= 0; j--) { const childN = n.childNodes[j]; - if (this.movedSet.has(childN) || this.addedSet.has(childN)) - return; - genAddsQueue.push([childN, undefined]); } if (hasShadowRoot(n)) { for (let j = n.shadowRoot.childNodes.length - 1; j >= 0; j--) { const childN = n.shadowRoot.childNodes[j]; - if (this.movedSet.has(childN) || this.addedSet.has(childN)) - return; - this.processedNodeManager.add(childN, this); genAddsQueue.push([childN, n]); } @@ -746,7 +735,8 @@ export default class MutationBuffer { } } - m.removedNodes.forEach((n) => { + for(let i = 0; i < m.removedNodes.length; i++) { + const n = m.removedNodes[i]; const nodeId = this.mirror.getId(n); const parentId = isShadowRoot(m.target) ? this.mirror.getId(m.target.host) @@ -793,7 +783,7 @@ export default class MutationBuffer { }); } this.mapRemoves.push(n); - }); + }; break; } default: diff --git a/packages/rrweb/src/record/processed-node-manager.ts b/packages/rrweb/src/record/processed-node-manager.ts index c5c3490dab..f68225424b 100644 --- a/packages/rrweb/src/record/processed-node-manager.ts +++ b/packages/rrweb/src/record/processed-node-manager.ts @@ -5,14 +5,11 @@ import type MutationBuffer from './mutation'; */ export default class ProcessedNodeManager { private nodeMap: WeakMap> = new WeakMap(); - private active = false; public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) { const buffers = this.nodeMap.get(node); - return ( - buffers && Array.from(buffers).some((buffer) => buffer !== thisBuffer) - ); + return buffers?.has(thisBuffer) } public add(node: Node, buffer: MutationBuffer) {