-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Preflight Checklist
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
What package is this feature request for?
rrweb
Problem Description
The full snapshot serialization process takes a significant amount of time, blocking the UI thread. I spent some time analyzing the process and noticed that there is a relatively expensive closest
function call for each text node, which can be avoided.
Proposed Solution
Within the snapshot serialization, I refined the method by which rrweb determines if text should be masked. Presently, for every individual text node during recursion, the closest method is invoked to ascertain if the node is a descendant of an element marked for masking. I modified this by passing the masking flag directly as a parameter to the recursion function, thereby eliminating superfluous lookups.
Alternatives Considered
N/A
Additional Information
I ran a series of performance measurements for the full snapshot serialization of a document generated by the following code:
for (let i1 = 0; i1 < 100; i1++) {
let parent = document.createElement("div");
document.getElementById("container").append(parent);
for (let i2 = 0; i2 < 100; i2++) {
let child = document.createElement("div");
child.innerText = `DIV ${i1} - ${i2}`;
parent.append(child);
parent = child;
}
}
The original function takes avg 34.55 ms
while optimized is avg 27.35 ms
.