Fix game freeze when pressing Play Game with multiple saves#430
Open
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
Open
Fix game freeze when pressing Play Game with multiple saves#430MCbabel wants to merge 1 commit intosmartcmd:mainfrom
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
Conversation
|
This is an issue with all versions of legacy IIRC, would love to see this fix be ported over to more platforms |
Contributor
Author
|
Yes, I kind of thought that it was a general problem |
Collaborator
|
I'm not sure this is the best fix for this realistically. It'd make more sense to resolve whatever part of the routine is taking so long to simply read a world name rather than potentially having visual lag on loading the world names IMO. |
Contributor
Author
|
you're right, I'm working on a better fix for this bug. |
0566d15 to
f93fbbf
Compare
Optimize ReadLevelNameFromSaveFile() to avoid reading entire save files into memory. For uncompressed saves: use seek-based file I/O to read only the header, file table, and level.dat entry (~100 KB instead of 10-50+ MB). For compressed saves: use a levelName.cache sidecar file so the full decompression only happens once; subsequent loads read the small cache file instantly. Previously, the function read and decompressed entire save files on the main thread for every save in a single frame, causing a multi-second freeze that scaled with the number of saves. Fixes smartcmd#409
bb05069 to
cb498a9
Compare
Contributor
Author
|
Well, that should be a better fix. Let me know what you think. @codeHusky |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix game freeze when pressing "Play Game" with multiple saved worlds. The freeze duration scaled linearly with the number of saves.
Changes
Previous Behavior
Pressing "Play Game" caused the game to freeze for several seconds. The freeze worsened with more saved worlds (e.g., 3+ saves caused noticeable freezing, 10+ saves caused multi-second hangs).
Root Cause
ReadLevelNameFromSaveFile()inUIScene_LoadOrJoinMenu.cppwas called synchronously for every save in a single frame during thetick()function. This function reads entire save files (10-50+ MB each), decompresses them if compressed, and parses NBT data to extract the level name — all on the main thread in one go.New Behavior
The save list appears immediately with fallback names (save folder timestamps). Real level names are loaded progressively, one save per tick, using
setButtonLabel()to update each entry. No freeze occurs regardless of the number of saves.Here is a short video showing the behavior before and after: https://youtu.be/5VKAjRbnsX4
It's hard to see, but it really becomes very noticeable with many worlds.
Fix Implementation
m_iDeferredNameIndexandm_sortedSaveIdxmember variables toUIScene_LoadOrJoinMenuto track deferred loading state.ReadLevelNameFromSaveFile()for each save.setButtonLabel().Related Issues