mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-23 06:41:56 -06:00
Try to reduce re-allocations a bit in resolveConflictsV2
This commit is contained in:
parent
83e4a67194
commit
665ca9c6cc
|
@ -778,7 +778,8 @@ func (v *StateResolution) resolveConflictsV2(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
notConflicted, conflicted []types.StateEntry,
|
notConflicted, conflicted []types.StateEntry,
|
||||||
) ([]types.StateEntry, error) {
|
) ([]types.StateEntry, error) {
|
||||||
eventIDMap := make(map[string]types.StateEntry)
|
estimate := len(conflicted) + len(notConflicted)
|
||||||
|
eventIDMap := make(map[string]types.StateEntry, estimate)
|
||||||
|
|
||||||
// Load the conflicted events
|
// Load the conflicted events
|
||||||
conflictedEvents, conflictedEventMap, err := v.loadStateEvents(ctx, conflicted)
|
conflictedEvents, conflictedEventMap, err := v.loadStateEvents(ctx, conflicted)
|
||||||
|
@ -800,18 +801,20 @@ func (v *StateResolution) resolveConflictsV2(
|
||||||
|
|
||||||
// For each conflicted event, we will add a new set of auth events. Auth
|
// For each conflicted event, we will add a new set of auth events. Auth
|
||||||
// events may be duplicated across these sets but that's OK.
|
// events may be duplicated across these sets but that's OK.
|
||||||
authSets := make(map[string][]*gomatrixserverlib.Event)
|
authSets := make(map[string][]*gomatrixserverlib.Event, len(conflicted))
|
||||||
var authEvents []*gomatrixserverlib.Event
|
authEvents := make([]*gomatrixserverlib.Event, 0, estimate*3)
|
||||||
var authDifference []*gomatrixserverlib.Event
|
authDifference := make([]*gomatrixserverlib.Event, 0, estimate)
|
||||||
|
|
||||||
// For each conflicted event, let's try and get the needed auth events.
|
// For each conflicted event, let's try and get the needed auth events.
|
||||||
|
neededStateKeys := make([]string, 16)
|
||||||
|
authEntries := make([]types.StateEntry, 16)
|
||||||
for _, conflictedEvent := range conflictedEvents {
|
for _, conflictedEvent := range conflictedEvents {
|
||||||
// Work out which auth events we need to load.
|
// Work out which auth events we need to load.
|
||||||
key := conflictedEvent.EventID()
|
key := conflictedEvent.EventID()
|
||||||
needed := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{conflictedEvent})
|
needed := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{conflictedEvent})
|
||||||
|
|
||||||
// Find the numeric IDs for the necessary state keys.
|
// Find the numeric IDs for the necessary state keys.
|
||||||
var neededStateKeys []string
|
neededStateKeys = neededStateKeys[:0]
|
||||||
neededStateKeys = append(neededStateKeys, needed.Member...)
|
neededStateKeys = append(neededStateKeys, needed.Member...)
|
||||||
neededStateKeys = append(neededStateKeys, needed.ThirdPartyInvite...)
|
neededStateKeys = append(neededStateKeys, needed.ThirdPartyInvite...)
|
||||||
stateKeyNIDMap, err := v.db.EventStateKeyNIDs(ctx, neededStateKeys)
|
stateKeyNIDMap, err := v.db.EventStateKeyNIDs(ctx, neededStateKeys)
|
||||||
|
@ -821,7 +824,7 @@ func (v *StateResolution) resolveConflictsV2(
|
||||||
|
|
||||||
// Load the necessary auth events.
|
// Load the necessary auth events.
|
||||||
tuplesNeeded := v.stateKeyTuplesNeeded(stateKeyNIDMap, needed)
|
tuplesNeeded := v.stateKeyTuplesNeeded(stateKeyNIDMap, needed)
|
||||||
var authEntries []types.StateEntry
|
authEntries = authEntries[:0]
|
||||||
for _, tuple := range tuplesNeeded {
|
for _, tuple := range tuplesNeeded {
|
||||||
if eventNID, ok := stateEntryMap(notConflicted).lookup(tuple); ok {
|
if eventNID, ok := stateEntryMap(notConflicted).lookup(tuple); ok {
|
||||||
authEntries = append(authEntries, types.StateEntry{
|
authEntries = append(authEntries, types.StateEntry{
|
||||||
|
|
Loading…
Reference in a new issue