Skip to content

[GEN][ZH] Refactor the recorder class to use a ramfile for replay playback. #1233

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Mauller
Copy link

@Mauller Mauller commented Jul 6, 2025

This PR converts the Recorder class to use the game file system for replay loading and playback.

This was required to allow the use of a RAMFile which allows the replay to be fully loaded into ram while being accessed through the common file handling interface.

This will need some testing in headless playback, i saw a small improvement in replay playback times under normal circumstances. But the biggest improvements will likely be under headless mode.

When other bottlenecks are removed in future, this change should show bigger contributions to replay playback speed.

@Mauller
Copy link
Author

Mauller commented Jul 6, 2025

@helmutbuhler @roossienb Would be worth giving this a test under headless to see what impact it has overall.

@Mauller Mauller self-assigned this Jul 6, 2025
@Mauller Mauller added Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Major Severity: Minor < Major < Critical < Blocker labels Jul 6, 2025
@helmutbuhler
Copy link

@helmutbuhler @roossienb Would be worth giving this a test under headless to see what impact it has overall.

I did 4 runs with several replays in sequential order for each run. 2 runs without this PR, 2 runs with this PR:
Total time of all replays in each run without this PR: 0:08:51 and 0:09:04
With this PR: 0:08:44 and 0:08:49

The times in more details are here:
ramtest.zip

So is this a significant improvement or just random noise? I don't know...

But I should also mention that I don't see any significant diskaccess when simulating replays, not even when doing 24 replays in parallel.

@Mauller
Copy link
Author

Mauller commented Jul 7, 2025

That is fair, we should see more improvements coming from this change when other bottlenecks during playback are removed.

There won't be significant amounts of disk access overall, it's just the fact it's a lot of small reads that happen. Which most drives don't like, but overall reading from disk is always a bottleneck compared to RAM.

This refactor also makes the playback file handling code easier to understand as well. The writing code is another matter entirely but i left that in place to use the original m_file and it is not that big an issue to convert it over to use the game file system.

@Mauller Mauller marked this pull request as ready for review July 7, 2025 08:59
@Mauller
Copy link
Author

Mauller commented Jul 10, 2025

This should be good to go if we wanted to consider using this change.

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

I was hoping for more performance gains but what helmut measured does not look exciting. We can still move forward with this change because it is technically an improvement.

m_replayFile = NULL;
}
else {
m_replayFile = m_replayFile->convertToRAMFile();
Copy link

Choose a reason for hiding this comment

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

This means that replay playback loses the ability for file streaming, aka reading a replay while it is being written to. Can we make this configurable in a way?

Copy link
Author

Choose a reason for hiding this comment

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

is it common to do this? i could look at adding an option in the options.ini to allow it to disable using the ram file if set, otherwise use the ram file by default.

Copy link

Choose a reason for hiding this comment

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

As far as I am aware Legionnaire uses this. Note that the LocalFile has a performance issue:

I am currently looking into that.

@Mauller Mauller force-pushed the refactor-replay-playback-use-ramfile branch from 5697465 to ce20c35 Compare July 12, 2025 17:23
@Mauller
Copy link
Author

Mauller commented Jul 12, 2025

updated with a rename to the original m_file to call it m_recordingFile to differentiate it from the replay playback file.

@helmutbuhler
Copy link

I was hoping for more performance gains but what helmut measured does not look exciting. We can still move forward with this change because it is technically an improvement.

@roossienb mentioned that he has heavy diskaccess during simulation. Maybe he can test whether this PR is an improvement.

@roossienb
Copy link

I was hoping for more performance gains but what helmut measured does not look exciting. We can still move forward with this change because it is technically an improvement.

@roossienb mentioned that he has heavy diskaccess during simulation. Maybe he can test whether this PR is an improvement.

Tried to do some with running -jobs 100 for 300 replays and pushing it to the limit. Got 512 seconds, 1019 seconds and 842 seconds. Way too much noise and other factors to get a proper performance analysis.

@helmutbuhler
Copy link

I was hoping for more performance gains but what helmut measured does not look exciting. We can still move forward with this change because it is technically an improvement.

@roossienb mentioned that he has heavy diskaccess during simulation. Maybe he can test whether this PR is an improvement.

Tried to do some with running -jobs 100 for 300 replays and pushing it to the limit. Got 512 seconds, 1019 seconds and 842 seconds. Way too much noise and other factors to get a proper performance analysis.

Unless you have some monster pc, -jobs 100 will just run the scheduler crazy ;) I suggest put the number after -jobs as many cores you have, and then watch in taskmanager whether disk utilization is better when this pr is applied. Or run without jobs and measure the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker 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.

4 participants