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

Remove Map references from MapPreview. #10697

Merged
merged 9 commits into from Feb 7, 2016

Conversation

pchote
Copy link
Member

@pchote pchote commented Feb 5, 2016

Closes #10433.

This removes the ram-hogging Map references from MapPreview. The trade-off is that it takes (significantly) longer to generate the previews in the map chooser. A future PR will reduce this delay by introducing a custom map parsing object that only loads the minimum amount of data required to generate a map preview.

This also removes the visible janks when selecting a map with custom rules in the lobby and missions in the mission browser. It also gets us another step closer to oramod packages.

I have not tested that this actually reduces the memory usage of dedicated servers, but these changes will stand on their own merit even if that does not pan out (which would be very surprising).

@pchote pchote changed the title Map cleanup part 2 Remove Map references from MapPreview. Feb 5, 2016
@pchote
Copy link
Member Author

pchote commented Feb 5, 2016

Confirmed that this reduces the memory usage by ~600MB after loading the RA mod (and generating the map previews) with the resource center maps synced.

@@ -26,7 +26,8 @@ public class LobbyLogic : ChromeLogic
{
static readonly Action DoNothing = () => { };

public MapPreview Map = MapCache.UnknownMap;
public MapPreview MapPreview = MapCache.UnknownMap;
public Map Map = null;
Copy link
Member

Choose a reason for hiding this comment

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

You're missing null checks in a few places when accessing this field in LobbyMapPreviewLogic.cs and LobbyLogic.cs that cause crashes if the preview is slow to generate. This also isn't assigned in a thread-safe manner from the worker thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure about this? It shouldn't be any different to what we were already doing - i've just moved the reference from inside the MapPreview to here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes - you can more easily repro these crashes by simply returning from the worker threads without actually generating the previews.

Here's a few I can see offhand:
LobbyMapPreviewLogic.cs#L28
LobbyMapPreviewLogic.cs#L59
LobbyLogic.cs#L193
LobbyLogic.cs#L320

@RoosterDragon
Copy link
Member

Although the thread-safety worries me in general - if the follow up PR comes along fairly promptly and fixes things by introducing a new parser that doesn't have these issues - then I'm otherwise happy to take this.

@pchote
Copy link
Member Author

pchote commented Feb 6, 2016

Fixed the LobbyLogic thread safety issues (you can verify this by adding a Thread.Sleep at the start of the thread body at ~L754). As discussed on IRC the other thread safety issues already exist in the current code.

@abcdefg30
Copy link
Member

Needs a rebase.

@penev92
Copy link
Member

penev92 commented Feb 6, 2016

👍

@pchote
Copy link
Member Author

pchote commented Feb 6, 2016

Rebased.

@obrakmann
Copy link
Contributor

Looks good to me. Memory usage for me on the ra main menu with disabled shellmap is down about 20 MB compared to bleed (and about 70/80 MB compared to release). CPU usage compared to release is down by about 10%, btw. Nice. 👍

obrakmann added a commit that referenced this pull request Feb 7, 2016
Remove Map references from MapPreview.
@obrakmann obrakmann merged commit 1df728a into OpenRA:bleed Feb 7, 2016
@obrakmann
Copy link
Contributor

Added the Changelog entry to the rest of the filesystem stuff.

@pchote pchote deleted the map-cleanup-part-2 branch February 27, 2016 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MapPreview should not hold a live reference to Map
5 participants