Skip to content
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

optimize isParentRemoved for large remove lists #1368

Closed

Conversation

mdellanoce
Copy link
Contributor

@mdellanoce mdellanoce commented Dec 6, 2023

Encountered a mutation that removes ~1400 nodes. Noticed a lot of the processing time was tied up in isParentRemoved, which repeatedly does an iterative search of the removes array. I added a map (nodeId => index in removes array) to speed up this process. See before/after images below:

Before:
image

After:
image

I didn't see a difference in the existing benchmarks, even though one of them involves removing a lot of nodes. The problem functionality shown in the profiles above involved scrolling through a large table that would dynamically remove/add pages of data as you scroll.

Copy link

changeset-bot bot commented Dec 6, 2023

🦋 Changeset detected

Latest commit: c68b3f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
rrweb Patch
rrweb-snapshot Patch
rrdom Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/types Patch
@rrweb/web-extension Patch
rrvideo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -688,6 +690,7 @@ export default class MutationBuffer {
? true
: undefined,
});
this.removesMap.set(nodeId, this.removes.length - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the rhs of this set here; it doesn't seem significant.
Should the data structure be a Set instead of a Map?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's true, then rather than adding another variable that needs to be maintained, we could convert the this.removes type into a Map indexed by nodeId new Map<number, removedNodeMutation>();
and then when the payload is emitted, convert to the expected array:

-removes: this.removes
+removes: Array.from(this.removes.values())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the map was unnecessary before, changed removes to just be a map of the id to the mutation as you suggested

@colingm colingm force-pushed the md-isparentremoved-optimization branch from 6855186 to c68b3f2 Compare May 1, 2024 19:06
@eoghanmurray
Copy link
Contributor

I think this has been superseded by #1543 which no longer does the expensive removes.some((r) => r.id === parentId)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants