Project-RT / RandomTweaker

Provides many more mods support and great features for CraftTweaker.
https://www.curseforge.com/minecraft/mc-mods/randomtweaker
MIT License
21 stars 8 forks source link

This function took about 2 seconds `ink.ikx.rt.impl.mods.crafttweaker.CraftTweakerExtension.registerAllClass()` #79

Closed Krutoy242 closed 7 months ago

Krutoy242 commented 7 months ago

Im profiled my E2E-E modpack and found that this function took 1.6 seconds to execute.

image

https://spark.lucko.me/1gJaCkUPrm?hl=301592

This is small in comparison to whole modpack, but since i have ~400 mods, i want to be sure each second spent by any mod is improving modpack and not an accidental bug😅 1.6 seconds is concerning for a single mod, when 200 of 400 mods loads in less than 0.1 second.

What does this function do? If it required for some mod feature, how can i disable this feature?

ikexing-cn commented 7 months ago

CraftTweaker compat, disabling it will not allow you to use any of mod features

Krutoy242 commented 7 months ago

Strange. All other mods that have CraftTweaker compat doesn't require this amount of time to initialize. Does RandomTweaker using some kind of special mechanics to register compat?

friendlyhj commented 7 months ago

I'm curious how much time crafttweaker.mc1120.CraftTweaker.onPreInitialization() takes?

Krutoy242 commented 7 months ago

I'm curious how much time crafttweaker.mc1120.CraftTweaker.onPreInitialization() takes?

2.9 sec image

https://spark.lucko.me/1gJaCkUPrm?hl=3068

friendlyhj commented 7 months ago

So we move crt register stuff to zenutils. Then can you tell how much time zenutils preinit takes?

Krutoy242 commented 7 months ago

I will test it later. Write please what class and method should I search for?

friendlyhj commented 7 months ago

youyihj.zenutils.ZenUtils.readSidedZenRegisters()

Krutoy242 commented 7 months ago

200ms https://spark.lucko.me/GU0xBk6eeB?hl=196627 image

This is not relevant to the problem, just my curiosity - what was it? Did RandomTweaker use some unusual methods that other mods don't use? Did it do any unnecessary calculations during initialization?

friendlyhj commented 7 months ago

A zenclass should be registered when two mods are installed. For example, custom botania flowers should be enabled only contenttweaker and botania are installed. However, CraftTweaker API only allows to add a single mod dependency of zenclass. RandomTweaker has to add a special way to register these classes. Recently, ZenUtils added the same mechanism to implement it, so we migrated to zenutils. 2.9s -> 200ms, looks like RandomTweaker code is low performace.