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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow save games - Solution proposal #617

Closed
wants to merge 1 commit into from

Conversation

MadShadow-
Copy link

I found a few possibilities to speed up the save game process significantly.

In the serialize class, I changed the compression level from Best Compression to Best Speed. Files sizes are roughly the same, but without the attempts to perfect compression, the saving is a lot faster.

I also reduced the number of files created by collecting all npc and mob data in a respective single file. See npc and vob cpp.

!! This breaks load/save game compatibility to previous versions of course !!

To me my changes look innocent, but I might have introduced bugs. 馃悶

Further thoughts

  • interactive objects still end up as single files.. but they are way less, so don't have much impact in this world. In theory they could need the same improvement.
  • The preview image is still a 4MB full screen image, which is unnecessary. (I've seen new commits regarding save game image size?)

- serialize class prefers speed over compression
- npcs and mobs don't create directoy files. instead everything is stored in single file
@MadShadow- MadShadow- mentioned this pull request May 6, 2024
@Try
Copy link
Owner

Try commented May 6, 2024

Hi, @MadShadow- !

Unfortunately, I have to reject this PR, most of it at least. We can't drop save-game compatibility support - this is strong most reason. While not really specified, but at least 1year old save should be compatible.

I changed the compression level from Best Compression to Best Speed

Is it really faster, or it's side effect of larger files? Can you provide numbers, to illustrate the performance gain?

@MadShadow-
Copy link
Author

Is it really faster, or it's side effect of larger files? Can you provide numbers, to illustrate the performance gain?

image

I saved 3 games on each run. Left is MZ_BEST_COMPRESSION and right is MZ_BEST_SPEED. 3 seconds faster on my machine.

gamesession.cpp

void GameSession::save(Serialize &fout, std::string_view name, const Pixmap& screen) {
  SaveGameHeader hdr;
  hdr.version   = Serialize::Version::Current;
  hdr.name      = name;
  hdr.world     = wrld->name();

  using std::chrono::high_resolution_clock;
  using std::chrono::duration_cast;
  using std::chrono::duration;
  using std::chrono::milliseconds;

  auto t1 = high_resolution_clock::now();


  {
  time_t now = std::time(nullptr);
  tm*    tp  = std::localtime(&now);
  hdr.pcTime = *tp;
  }
  hdr.wrldTime  = wrldTime;
  hdr.playTime  = ticks;
  hdr.isGothic2 = Gothic::inst().version().game;

  // [savegame code]

  auto t2 = high_resolution_clock::now();

  /* Getting number of milliseconds as an integer. */
  auto ms_int = duration_cast<milliseconds>(t2 - t1);

  /* Getting number of milliseconds as a double. */
  duration<double, std::milli> ms_double = t2 - t1;

  std::cout << ms_int.count() << "ms\n";
  std::cout << ms_double.count() << "ms\n";
  }

@Try Try marked this pull request as draft May 11, 2024 19:33
@Try Try closed this May 18, 2024
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.

None yet

2 participants