Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Nov 2, 2025

This change simplifies and improves the implementation of MapCache to prevent expensive reoccurring redundant map cache reads. It also removes DEBUG_LOG in buildMapListForNumPlayers because it is a spammy log that adds stalling.

Originally, the implementation in MapCache::updateCache was a total munkee disaster. Very complicated and inefficient. This change turned out to be half refactor, half performance optimization.

Problems in MapCache were:

  • Standard and User Map Cache INI loaded on every call to MapCache::updateCache, even if already loaded
  • Too much different logic cramped into MapCache::loadUserMaps
  • Overcomplicated logic around TheGlobalData->m_buildMapCache
  • Overcomplicated and inefficient logic around std::map<AsciiString, Bool> m_seen
  • Standard Maps Cache built in two code paths
  • Standard Maps Cache built after existing Cache was already loaded, causing poisened Map Cache generation

All this is fixed.

Performance measurement

Measured in optimized vs2022 build, with RTS_DEBUG.

Map List Click Original Time Optimized Time (This Change)
System Maps 203 ms 62 ms
User Maps 313 ms 62 ms

TODO

  • Replicate in Generals

…event expensive reoccurring redundant map cache reads
@xezon xezon added GUI For graphical user interface Major Severity: Minor < Major < Critical < Blocker Performance Is a performance concern Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels Nov 2, 2025
Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

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

Looks good overall, only a few points to help clear up the logic.

TheFileSystem->createDirectory(mapDir);

filepath.concat(m_mapCacheName);
FILE *fp = fopen(filepath.str(), "w");
Copy link

Choose a reason for hiding this comment

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

If we are rewriting this, should we make use of the game file system like we did with the recorder class instead of raw C file handling? It might make some of the file handling a bit cleaner.

could be someting for a followup PR at some point.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe yes. I did not specifically touch the file handling stuff, just nearby code.

Choose a reason for hiding this comment

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

I can do that as a follow up PR.

Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

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

Looks okay to me now, could probably be more optimised in the future but the current gains in performance are pretty decent from the current refactor.

@Mauller Mauller added the Approved Pull Request was approved label Nov 10, 2025
@xezon
Copy link
Author

xezon commented Nov 10, 2025

Some things could be moved out of the update function into init function.

Replicated in Generals without conflicts.

@xezon xezon merged commit d433899 into TheSuperHackers:main Nov 11, 2025
18 checks passed
@xezon xezon deleted the xezon/optimize-mapcache branch November 11, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved Pull Request was approved Gen Relates to Generals GUI For graphical user interface Major Severity: Minor < Major < Critical < Blocker Performance Is a performance concern Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants