-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request]: Optimize full snapshot serialization performance #1337
Comments
Would it be possible to re-run your benchmark measurements against #1349 ? I think my approach adds a little less complexity than your one, so if it performs just as good then I'd prefer to go with it, but you'll have to let me know if performance is okay! |
Thanks for getting back to me. I'll work on this during next couple of days and let you know. Thanks. |
I like the idea of having all masking logic in the same place; the code is more maintainable. It's definitely worth merging your optimization. |
There are some good ideas with your approach of doing an upfront |
I've just updated my PR with an added check which might reduce the number of calls to |
Hey @eoghanmurray . This may be a stupid question but isn't the snapshot process synchronous thereby precluding any possible DOM mutations while the snapshot code is running? |
Preflight Checklist
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:
The original function takes avg
34.55 ms
while optimized is avg27.35 ms
.The text was updated successfully, but these errors were encountered: