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

Optimize rating initialization #839

Merged
merged 2 commits into from
Sep 25, 2021

Conversation

Askaholic
Copy link
Collaborator

I had a look at the server profile generated after the last update, and it looks like the rating initialization was being called an excessive amount. This is mostly because it gets invoked both when generating game_info as well as player_info messages.

In the game_info messages it would be called even if the rating data wasn't actually needed, just because it had been easier to write that ways. Now, it checks whether rating enforcement is enabled first and only queries the rating if it is. I also added some caching to the rating computation itself so that the queries generated by the player_info message creation will now short circuit the majority of the time.

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #839 (4828ee3) into develop (474bb1f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
server/games/game.py 95.67% <ø> (-0.03%) ⬇️
server/players.py 100.00% <100.00%> (ø)
server/rating.py 93.90% <100.00%> (+0.31%) ⬆️

Determine if a player should see this game in their games list.

Note: This is a *hot* function, it can have significant impacts on
performance.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it because of the rating initialization? It doesn't become clear, why this comment on performance is here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It’s there because this is now the second time I’ve had to optimize something that was added to that function because it showed up in the profiler.


chained_ratings["global"] = (1000, 50)

assert chained_ratings["tmm_2v2"] == chained_ratings["tmm_2v2"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a typo? How will this ever fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This checks that the rating is cached and not recomputed. If it were recomputed we would get different mock objects for the two calls.

@Askaholic Askaholic merged commit cf4e9b0 into FAForever:develop Sep 25, 2021
@Askaholic Askaholic deleted the optimize-rating-initialization branch September 25, 2021 06:27
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.

2 participants