Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop doing O(n^2) work to find event's home (#3227)
* Stop doing O(n^2) work to find event's home 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> * Add type to `parentEvent` Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: J. Ryan Stinnett <jryans@gmail.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
- Loading branch information