SuperMartijn642 / SuperMartijn642sCoreLib

14 stars 2 forks source link

[Feature] Improve performance of model overwrites #23

Closed embeddedt closed 1 year ago

embeddedt commented 1 year ago

Is your feature request related to a problem? Please describe.

Currently model overwrites add about 11 seconds to launch time (measured via profiling). Based on a code analysis, I suspect the problem is in the way you handle ModelBakeEvent.

https://github.com/SuperMartijn642/SuperMartijn642sCoreLib/blob/aa78af8104a614e4e844c02fe85dd09b572e96c1/src/main/java/com/supermartijn642/core/registry/ClientRegistrationHandler.java#L589-L608

This code has relatively poor time complexity because it requires iterating over every model in the registry and then running every model overwrite's predicate to see if it matches.

image

Describe the solution you'd like

A potentially better solution would be to implement the modelOverwrites list as a hash map with ResourceLocations or ModelResourceLocations as keys. If necessary multiple entries can be added to this map within the various registration methods to handle replacing multiple models.

The model bake event handler then only needs to iterate over the model registry exactly once, check if that location is in the HashMap, and if so obtain its replacement. This should avoid spending large quantities of time testing each model.

This probably affects 1.16, 1.18, and 1.19, but my profiling has been done on 1.18 using the Enigmatica 8 modpack.

SuperMartijn642 commented 1 year ago

Whoops that code is left over from when I couldn't get the overwrites to work. I changed it to just a predicate so I could more easily test it. However, I probably just moved on to fixing some other issues once it was working and then forgot about. But damn 11 seconds really is a lot, especially for what is likely only a couple blocks.

I might have some time later today and if not, definitely tomorrow, so shouldn't take too long to get fixed.

SuperMartijn642 commented 1 year ago

I fixed it now in version 1.1.5.

Thank you for notifying me of the issue and for the excellent report 🙂