feat: only init managers when they are first accessed #410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This initalizes managers in a static constructor instead of initialising all of them at the start. The first time a manager is accessed via a member like events or a singelton access from a mod, it will be initalized.
The advantage is that Jotunn will load much faster with a small mod count, as only the necessary managers are loaded and initalized. Also, if some part breaks after a Valheim update, only called managers are effected.
For a large modpack, there's practically no difference as most managers are used anyway. The startup time without additional mods drops from about 800ms to about 150ms, which finally makes Jotunn lighweight.
The only possible problem is that a manager might be initalized too late and certain patches won't apply. Although this is rather unlikely, as most is happening in the Awake or Start methods of mods anyway. After testing a small number of mods, no issues were found. Nevertheless, extended testing is needed.