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

improve rrdom performance #1127

Merged
merged 18 commits into from
Feb 14, 2023
Merged

improve rrdom performance #1127

merged 18 commits into from
Feb 14, 2023

Conversation

YunFeng0817
Copy link
Member

@YunFeng0817 YunFeng0817 commented Feb 12, 2023

Performance Issue

In the repo benchmark-events, I uploaded one huge event data file. This file is recorded on the page https://bugs.chromium.org/p/chromium/issues/list?mode=grid with the rrweb browser extension.
The performance of rrdom is challenged in this situation.
image
From the screenshot of the performance profile, we can see that the contains function in rrdom is a performance bottleneck. Besides, as @Yuyz0112 has mentioned before (#853 (comment)), the current implementation for storing nodes with array data structure may cause a lot of iteration when inserting new nodes into the tree.

benchmark result before the optimization

    ┌─────────┬─────────────────────────────────────────────┬───────┬───────────────────┬────────────────────┐
    │ (index) │                    title                    │ times │     duration      │     durations      │
    ├─────────┼─────────────────────────────────────────────┼───────┼───────────────────┼────────────────────┤
    │    0    │ 'real events recorded on bugs.chromium.org' │   3   │ 4899.333333333333 │ '4870, 4842, 4986' │
    └─────────┴─────────────────────────────────────────────┴───────┴───────────────────┴────────────────────┘

Optimization

  1. Refactor: change the data structure of childNodes from array to linked list
  2. Improve the performance of the "contains" function. New algorithm will reduce the complexity from O(n) to O(logn)

benchmark result after the optimization

    ┌─────────┬─────────────────────────────────────────────┬───────┬──────────┬────────────────────┐
    │ (index) │                    title                    │ times │ duration │     durations      │
    ├─────────┼─────────────────────────────────────────────┼───────┼──────────┼────────────────────┤
    │    0    │ 'real events recorded on bugs.chromium.org' │   3   │   2717   │ '2703, 2738, 2710' │
    └─────────┴─────────────────────────────────────────────┴───────┴──────────┴────────────────────┘

iShot_2023-02-12_22 28 28

After the optimization, from the performance profile, there's no more significant performance bottleneck in RRDom anymore. The performance improvement under this scenario is around 80%.

@changeset-bot
Copy link

changeset-bot bot commented Feb 12, 2023

🦋 Changeset detected

Latest commit: 3f6eb9e

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

This PR includes changesets to release 5 packages
Name Type
rrdom Major
rrdom-nodejs Major
rrweb Patch
rrweb-player Patch
rrweb-snapshot 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

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.

2 participants