nickc01 / WeaverCore

Core mod for all of my mods for Hollow Knight
https://nickc01.github.io/WeaverCore/
MIT License
14 stars 6 forks source link

game startup slowdown #13

Closed danirainy closed 8 months ago

danirainy commented 9 months ago

Hi!

First I really want to thank you for this amazing mod. I am using it to create new empty scenes and set up transition logics, and it is doing its job amazingly, saving me lots of time to invent the wheel myself. One small concern is that the game startup is slowing down quite noticeably, even though I am only adding entirely empty scenes (with doors only). Do you know the root cause of slowing down?

nickc01 commented 9 months ago

Not sure what would be causing the slowdowns, but i can add some timers into the modloading process and see what part is running the slowest.

It may also be dependent on the system specs. When i have some time, i can send you a custom version of WeaverCore, and you can then send me what the times are on your computer.

danirainy commented 9 months ago

Yeah let's do this when you have time. This will be very helpful

nickc01 commented 8 months ago

Sorry for taking a while. I had to get some other important things done first before I could take a look at this. In the latest development version of WeaverCore, I added some performance logs into the WeaverCore mod loading process. Each step of the loading process will print to ModLog the amount of time that has passed since WeaverCore first started loading, followed by a message. Here's an example log from my computer. WeaverCore starts loading at Timestamp 0 seconds, and finishes loading at timestamp 18.499 seconds.

ModLog.txt

One key thing I found that influences the length of time is the compression method used to pack your mod. When building your mod, there are three main compression methods you can pick from:

Build Settings Compression Method

On my machine, the NONE compression option resulted in the fastest load times. LZMA resulted in the slowest load times, and LZ4 was somewhere in between. Here's my results with Inferno King Grimm and WeaverCore:

When you can, be sure to use the latest develop version of WeaverCore and test the load times of your mod.

danirainy commented 8 months ago

Thanks for adding the perf log. Attached is my modlog. It took 60s to load on my computer and I don't see what's the bottleneck, looks like just generally slower at each step ModLog.txt

nickc01 commented 8 months ago

I think I got the issue fixed. The problem was that when WeaverCore was doing it's patching and initialization processes, it was looking through every DLL it could find, and attempting to find WeaverCore attributes, assetbundles, and other WeaverCore specific things in them. Since only a few DLLs actually use WeaverCore related things, this results in a massive waste of time. For partically large DLLS, like HKMirror and MMHOOK_Assembly-CSharp, this can add tons of time to the startup.

[INFO]:12.07 - Patching assembly MMHOOK_Assembly-CSharp [INFO]:13 - Finished patching assembly MMHOOK_Assembly-CSharp

[INFO]:9.26 - Patching assembly HKMirror [INFO]:11.904 - Finished patching assembly HKMirror

I was able to get this fixed through the use of a function I never heard about till now called Assembly.GetReferencedAssemblies, I am able to use this to see if a DLL depends on WeaverCore before doing a bunch of checking over it. I just pushed my changes to the latest develop branch, so you should be able to test it yourself.

I tested it myself, and even with a few mods installed, this brought down my startup time from 18.581 seconds to 10.478 seconds. This should also make the log file smaller, because WeaverCore doesn't need to do as much wasted processing as before.

danirainy commented 8 months ago

Thanks for the quick fix! You are super helpful! Looking forward to the an official release so that I can upgrade. :)

danirainy commented 8 months ago

I updated to latest dev to test your fix but my mod is not loading anymore :) ModLog.txt

nickc01 commented 8 months ago

Course it's crashing right where I try to use the Assembly.GetReferencedAssemblies function. I'll see if I can come up with a workaround.

nickc01 commented 8 months ago

I updated to latest dev to test your fix but my mod is not loading anymore :) ModLog.txt

This should be fixed now. I created my own version of the Assembly.GetReferencedAssemblies function that shouldn't crash this time.

danirainy commented 8 months ago

I updated to latest dev to test your fix but my mod is not loading anymore :) ModLog.txt

This should be fixed now. I created my own version of the Assembly.GetReferencedAssemblies function that shouldn't crash this time.

Still doesn't load for me though. Error log looks the same. Attached is my source code and dll. Pls take a look when you have time. Thanks!

dll.zip PantheonOfZotesScenes-master.zip

nickc01 commented 8 months ago

The log shouldn't be the same though, since I'm using a different method for checking assembly dependencies. Are you sure the log is identical to the previous one? I can come up with a different method if it is still the same

nickc01 commented 8 months ago

I changed the load method to something that doesn't use Assembly.GetReferencedAssemblies. Could you try testing it again with the latest WeaverCore commit?

danirainy commented 8 months ago

Now it's working and the loading time is just 10s! Whatever you did it seems all working fine! Thanks so much for working on this.

I do have a last question about backward compatibility. So if I build my mod with this dev branch (or a future public release with the fix), and someone else want to load my mod, do they have to upgrade to a newer version of weavercore? If they don't, what happens ? (Slow loading time? Or just failure of loading?) This is kind of a reasonable question because Chinese community tends to not use mod installer and sometimes have outdated dependencies.

nickc01 commented 8 months ago

So if I build my mod with this dev branch (or a future public release with the fix), and someone else want to load my mod, do they have to upgrade to a newer version of weavercore? If they don't, what happens ? (Slow loading time? Or just failure of loading?) This is kind of a reasonable question because Chinese community tends to not use mod installer and sometimes have outdated dependencies.

It depends if your mod is using features/changes that are exclusive to the dev branch. I haven't really done a whole lot of changes to the dev branch, so it hopefully shouldn't break with the current release version, but there's no guarantee. If you want to test it out yourself, you can download the release version of WeaverCore, and attempt to load your mod (which was built with the dev version) with the release version. The only major changes I have made so far in the dev branch was adding Soul Totems, adding PersistentBoolItem/PersistentIntItem classes, and some other bug fixes. https://github.com/nickc01/WeaverCore/commits/develop/?since=2024-01-20&until=2024-02-19

danirainy commented 8 months ago

Yeah I just tried a release version of WeaverCore and it still loads (just slow loading time though). Thanks again :)