Skip to content

Conversation

@Ratio2
Copy link

@Ratio2 Ratio2 commented Dec 18, 2023

The order of combinations has changed slightly. Now the result is sorted according to the sorting of the input data.

Before these changes, matchmaking with override is very slow with more than 30 players:
players - time in seconds
10 - 1.1
20 - 1.9
22 - 2
24 - 2
26 - 3
28 - 8
30 - 28
32 - 118

The order of combinations has changed slightly. Now the result is sorted according to the sorting of the input data.
@CLAassistant
Copy link

CLAassistant commented Dec 18, 2023

CLA assistant check
All committers have signed the CLA.

@sesposito
Copy link
Member

Hello @Ratio2, can you elaborate a bit more on what this PR is doing to improve performance?

@Ratio2
Copy link
Author

Ratio2 commented Sep 23, 2024

Hello @Ratio2, can you elaborate a bit more on what this PR is doing to improve performance?

Input data:
func combineIndexes(from []*MatchmakerIndex, min, max int)
len(from) = 32
min = 2
max = 2

The function call duration is 118 seconds, since we have complexity O(N*2^N) from the input array size regardless of min/max. The loop for combinationBits := 1; combinationBits < (1 << length); combinationBits++ consists of 2^32 iterations, which is a lot, and there is also an inner loop for element := uint(0); element < length; element++.

The main idea of ​​the change is to not iterate over impossible combinations in the loop. If max = 2, then we are not interested in combinations of 3 or more elements.

iterium.Combinations generates all possible combinations of N elements.
rangeCombinations generates all possible combinations of 1..N elements. If the input is [a, b, c], then the output is [[a], [a, b], [a, c], [b], [b, c], [c]].

for passLength := range Range(1, 7).Chan() {
fmt.Println("Password Length:", passLength)

// Merge a slide into a string.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Merge a slide into a string.
// Merge a slice into a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants