Repository navigation
Map assets instead of reading the whole file on every open - #157
Open
xRookieFight wants to merge 1 commit into
Open
xRookieFight wants to merge 1 commit into
xRookieFight wants to merge 1 commit into
Conversation
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.
Joining a server has been taking 15 to 20 seconds (sometimes much longer) on the "Loading resources" / "Connecting to server" screen since roughly 1.26.20. Other launchers on the same machine and network join instantly.
Cause
Newer game versions pack textures into large
.brarchivefiles (for examplevanilla/__brarchive/textures/ui.brarchiveis about 16 MB andvanilla_1.21.90/__brarchive/textures/blocks.brarchiveabout 5.7 MB). While applying the server's resource pack stack, the game opens these archives once per entry throughAAssetManager_open.fake_assetmanagerread the entire file into astd::stringon every open and then copied it once more into theAAsset. With strace attached during a single join I counted around 19k archive opens, which adds up to roughly 73 GB read from disk plus the same amount copied in memory. Sampling/proc/<pid>/iowithout strace showedrchargrowing by about 1.4 GB/s for the whole loading screen and stopping exactly when the player spawned.On Android, uncompressed assets are memory mapped, so these repeated opens cost almost nothing there.
Fix
AAssetManager_opennowmmaps the file read only andAAssetreads from the mapping.AAsset_getBufferreturns the mapped pointer, so there is no read and no copy per open, and pages are only touched when the game actually reads them.AAsset_getBufferused to return a NUL terminated buffer, and some callers may treat it as text. The zero filled tail of the last mapped page keeps that guarantee, except when the size is an exact multiple of the page size. Those files and empty files are still read into a buffer.Testing
Built inside the flatpak SDK (org.kde.Sdk 6.10, clang 20) from mcpelauncher-manifest
ef9ceb8eand ran it with game version 1.26.51.1 against a server with a custom resource pack. The loading screen went from tens of seconds to an instant join, and textures, UI and the server pack render normally.