Only append the single event

This commit is contained in:
Neil Alexander 2022-02-24 10:35:56 +00:00
parent 47e7045ca4
commit 6340e3e27f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -851,15 +851,20 @@ func (v *StateResolution) resolveConflictsV2(
if err != nil { if err != nil {
return nil, err 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] { for _, event := range authSets[key] {
if _, ok := gotAuthEvents[event.EventID()]; !ok { if _, ok := gotAuthEvents[event.EventID()]; !ok {
authEvents = append(authEvents, authSets[key]...) authEvents = append(authEvents, event)
gotAuthEvents[event.EventID()] = struct{}{} 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 gotAuthEvents = nil // nolint:ineffassign
// This function helps us to work out whether an event exists in one of the // This function helps us to work out whether an event exists in one of the