-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Stop doing O(n^2) work to find event's home (eventShouldLiveIn
)
#3227
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In certain rooms (e.g. with many state changes hidden via user preferences), the events array presented to `eventShouldLiveIn` may contain 100s of events. As part of its various checks, `eventShouldLiveIn` would get an event's associated ID (reply / relation / redaction parent). It would then use `events.find` to search the entire (possibly large) `events` array to look for the parent. (This by itself seems sub-optimal and should probably change to use a map.) For many events in a room, there is no associated ID. Unfortunately, `eventShouldLiveIn` did not check whether the associated ID actually exists before running off to search all of `events`, resulting in O(n^2) work. This changes `eventShouldLiveIn` to first check that there is an associated ID before proceeding with its (slow) search. For some rooms, this change drastically improves performance from ~100% CPU usage to nearly idle. Signed-off-by: J. Ryan Stinnett <jryans@gmail.com>
github-actions
bot
added
the
Z-Community-PR
Issue is solved by a community member's PR
label
Mar 23, 2023
t3chguy
approved these changes
Mar 23, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise
Thanks for this!!
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
MadLittleMods
changed the title
Stop doing O(n^2) work to find event's home
Stop doing O(n^2) work to find event's home (Mar 23, 2023
eventShouldLiveIn
)
su-ex
added a commit
to SchildiChat/matrix-js-sdk
that referenced
this pull request
Apr 21, 2023
* Allow via_servers property in findPredecessor (update to MSC3946) ([\matrix-org#3240](matrix-org#3240)). Contributed by @andybalaam. * Fire `closed` event when IndexedDB closes unexpectedly ([\matrix-org#3218](matrix-org#3218)). * Implement MSC3952: intentional mentions ([\matrix-org#3092](matrix-org#3092)). Fixes element-hq/element-web#24376. * Send one time key count and unused fallback keys for rust-crypto ([\matrix-org#3215](matrix-org#3215)). Fixes element-hq/element-web#24795. Contributed by @florianduros. * Improve `processBeaconEvents` hotpath ([\matrix-org#3200](matrix-org#3200)). * Implement MSC3966: a push rule condition to check if an array contains a value ([\matrix-org#3180](matrix-org#3180)). * indexddb-local-backend - return the current sync to database promise … ([\matrix-org#3222](matrix-org#3222)). Contributed by @texuf. * Revert "Add the call object to Call events" ([\matrix-org#3236](matrix-org#3236)). * Handle group call redaction ([\matrix-org#3231](matrix-org#3231)). Fixes vector-im/voip-internal#128. * Stop doing O(n^2) work to find event's home (`eventShouldLiveIn`) ([\matrix-org#3227](matrix-org#3227)). Contributed by @jryans. * Fix bug where video would not unmute if it started muted ([\matrix-org#3213](matrix-org#3213)). Fixes element-hq/element-call#925. * Fixes to event encryption in the Rust Crypto implementation ([\matrix-org#3202](matrix-org#3202)).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In certain rooms (e.g. with many state changes hidden via user preferences), the events array presented to
eventShouldLiveIn
may contain 100s of events. As part of its various checks,eventShouldLiveIn
would get an event's associated ID (reply / relation / redaction parent). It would then useevents.find
to search the entire (possibly large)events
array to look for the parent. (This by itself seems sub-optimal and should probably change to use a map.)For many events in a room, there is no associated ID. Unfortunately,
eventShouldLiveIn
did not check whether the associated ID actually exists before running off to search all ofevents
, resulting in O(n^2) work.This changes
eventShouldLiveIn
to first check that there is an associated ID before proceeding with its (slow) search. For some rooms, this change drastically improves performance from ~100% CPU usage to nearly idle.Profile before
Profile after
Checklist
Here's what your changelog entry will look like:
🐛 Bug Fixes
eventShouldLiveIn
) (#3227). Contributed by @jryans.