[Suggestion] Optimize SearchTreeManager / ID remapping (if possible)
Lordmau5 opened this issue · 3 comments
Foreword
As there's no real other way that I can see to contact you (except via. E-Mail, which takes an annoying back and forth, too) and talk about this idea, I guess I'll just write a small issue / suggestion in regards to this 😄
The Problem
So in "average" mod packs (~170 mods) it takes like 10 seconds when you leave a server.
Now, I've done some profiling and 6 of those seconds seem to be Chisels & Bits re-doing it's model cache, meaning mod packs without that mod won't be affected by this, really.
The other 4 seem to be associated to the SearchTreeManager
(as in, Vanilla's creative search & recipe book).
SearchTreeManager
I've temporarily tried to replace the FMLCommonHandler.reloadSearchTrees
/ FMLClientHandler.reloadSearchTrees
method with an empty method so it doesn't do that.
Surely, I managed to leave a server 4 seconds faster. I haven't found any issues in Singleplayer with this either, so that's something.
However, I feel it could run into some issues at some point...
That's... basically all there is to this --- moving on...
The ID Remapping Event
As for the ID remapping event, that seems to be handled on Forge's end.
Now, not a big issue really, except I am not sure if there is a better way to do (and I assume it's probably something I should post on the Forge issue tracker and not here, but as these 2 things are causing long load times, I thought I might as well).
So, the ID remapping is being called in these 3 locations (all in net.minecraftforge.registries.GameData
):
freezeData
- This one is being called when the game is initializing (as in, when you start Minecraft)injectSnapshot
- From what it looks like, this is in "charge" of loading a world on Singleplayer, or rather,FMLContainer.readData
which in return is being called byFMLCommonHandler.handleWorldDataLoad
.revertToFrozen
- Stupidly named in my opinion, but this seems to be called when a world or server is being left. Being called fromFMLClientHandler.handleWorldClosing
,Loader.serverStopped
and in theFMLHandShakeClientState
.
Now, the one thing I don't understand here:
Why would you want to remap the IDs when you are leaving a server or leaving a world?
Wouldn't it be smarter to do it when you're actually trying to load a world?
It seems to do that when joining a server because otherwise... well, it wouldn't let you join any server, really, unless the registries are 1:1 the same.
Would some of these observations perhaps be useful in adding some new FoamFix optimisation features?
Regarding the SearchTreeManager: Can't do much. Except I can, and have. You might notice FoamFix 0.9.0 will replace SearchTreeManager.ITEMS with a proxy which uses JEI's search functionality - it's argualy slightly less RAM-efficient than vanilla's, but it's easier to remove vanilla's search tree and use JEI's than the other way around - besides, it lets you use JEI prefixes in the vanilla search menu. This saves RAM and loading times.
Dummying out the method you mentioned might be mostly harmless in 1.12, but come 1.13 (or with any mod which dynamically disables recipes during world load) it will not be harmless. I think my solution saves a significant amount of the loading time and RAM.
Regarding the ID remapping: revertToFrozen restores the IDs to the initial (pre-world-load) state.