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

Stop doing O(n^2) work to find event's home (eventShouldLiveIn) #3227

Merged
merged 2 commits into from
Mar 23, 2023

Commits on Mar 23, 2023

  1. 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>
    jryans committed Mar 23, 2023
    Configuration menu
    Copy the full SHA
    4479309 View commit details
    Browse the repository at this point in the history
  2. Add type to parentEvent

    Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
    jryans and t3chguy committed Mar 23, 2023
    Configuration menu
    Copy the full SHA
    5398fd3 View commit details
    Browse the repository at this point in the history