TerraformersMC / ModMenu

A menu for, you guessed it, mods!
MIT License
478 stars 141 forks source link

Provided screen factories causing unnecessary overhead when opening mod menu screen #584

Closed MrCrayfish closed 1 year ago

MrCrayfish commented 1 year ago

I'm currently using the API to provide config screens for other mods. As stated by the docs, I need to return a map of all the mods ids and their associated config screen factory. However ModMenuApi#getProvidedConfigScreenFactories is being called for every mod and library, and this means my provider is running 46 times at minimum (Fabric, it's libraries, and Mod Menu). My suggestion would be to call getProvidedConfigScreenFactories from each provider once, combine them and then request from that map.

Prospector commented 1 year ago

Good point, I am trying to figure out why I didn't do it like that to begin with, but can't come up with anything. I'll do what you suggested.

Prospector commented 1 year ago

So, it turns out this breaks a ton of mods that use config providers because they relied on the fact that it wasn't accessed until later... I may have to revert this until those mods have fixed their implementations. Affected mods so far seem to be Architectury and owo-lib

Prospector commented 1 year ago

I think I can fix it by delaying the accessing of the fields until the first time a config screen is requested, but it may cause a brief lag spike. At least it would only be one time instead of every time though.

MrCrayfish commented 1 year ago

Lazy initialize on the first time opening ModsScreen, that should fix compatibility.

Prospector commented 1 year ago

yup, that's basically what I did in 6.2.1