From 6340e3e27fe032f03a3ee2d05e93acb0a2e92bbf Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 24 Feb 2022 10:35:56 +0000 Subject: [PATCH] Only append the single event --- roomserver/state/state.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roomserver/state/state.go b/roomserver/state/state.go index ebb648827..fc12e4fbd 100644 --- a/roomserver/state/state.go +++ b/roomserver/state/state.go @@ -851,15 +851,20 @@ func (v *StateResolution) resolveConflictsV2( if err != nil { return nil, err } + + // Only add auth events into the authEvents slice once, otherwise the + // check for the auth difference can become expensive and produce + // duplicate entries, which just waste memory and CPU time. for _, event := range authSets[key] { if _, ok := gotAuthEvents[event.EventID()]; !ok { - authEvents = append(authEvents, authSets[key]...) + authEvents = append(authEvents, event) gotAuthEvents[event.EventID()] = struct{}{} } } } - // Let the GC get to this. + // Kill the reference to this so that the GC may pick it up, since we no + // longer need this after this point. gotAuthEvents = nil // nolint:ineffassign // This function helps us to work out whether an event exists in one of the