Cache the fake render environment used by game scenes - #123
Open
julian-perge wants to merge 1 commit into
Open
julian-perge wants to merge 1 commit into
julian-perge wants to merge 1 commit into
Conversation
GuidebookLevelRenderer#renderContent calls FakeRenderEnvironment.create() once per visible scene per frame, and each call built a fresh Connection, ClientPacketListener, ClientLevel and LocalPlayer before close() discarded them. Besides the allocation, constructing ClientPacketListener bootstraps PotionBrewing, which fires RegisterBrewingRecipesEvent, and constructing ClientLevel fires LevelEvent.Load, so every mod listening to either event redid its registration work on each frame a scene was visible. create() ignores its Level parameter, so the fake player does not depend on the scene being rendered. Keep it in a static field next to the RegistryAccess it was built from and rebuild only when Platform.getClientRegistryAccess() returns a different instance. GuideMEClient clears the cache on ClientPlayerNetworkEvent.LoggingOut so leaving a world does not pin that world's RegistryAccess.
This branch has not been deployed
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.
Fixes #106
GuidebookLevelRenderer#renderContentcallsFakeRenderEnvironment.create()once per visible scene per frame, and every call builds a fresh
Connection,ClientPacketListener,ClientLevelandLocalPlayerbeforeclose()throwsthem away again.
There is a second cost beyond the allocation. Constructing
ClientPacketListenerbootstraps
PotionBrewing, which firesRegisterBrewingRecipesEvent, andconstructing
ClientLevelfiresLevelEvent.Load. Any mod that listens toeither one redoes its registration work on every frame that a scene is visible.
In my ATM11 alpha mod-pack I counted just over 52,000 such registrations from three mods
in a single session, peaking at 419 per second while an AE2 guide page was open.
They accounted for 95% of the lines in my logfile.
The fake player does not depend on the scene being rendered.
create()alreadyignores its
Levelparameter, which is what makes caching safe here. It nowkeeps the built graph in a static field next to the
RegistryAccessit wasbuilt from, and rebuilds only when
Platform.getClientRegistryAccess()returnsa different instance. The rest of
create()is untouched, including theminecraft.playerswap thatclose()reverts.That is the approach @LegendaryRylex described in #106. On top of it,
GuideMEClientclears the cache onClientPlayerNetworkEvent.LoggingOut, soleaving a world does not pin that world's
RegistryAccess.I tested this on 26.1.2 in the pack described above. The registrations now
happen only at world join, and the guide pages that used to produce the bursts
no longer do.
#121 rewrites the same method while porting to 26.3, so whichever of the two
lands second will need a small rebase.