Improvement: Use EnumMap and fields for config #2033
Merged
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.
PR Reviews
When your PR is marked as ready for review, some of our maintainers will look through your code to make sure everything is good to go. In order to do this, they may request some changes you will need to do, or fix smaller stuff (like merge conflicts) for you. If a maintainer has reviewed your PR, make sure to pull any of their changes into your local project before doing more work on your code. Having maintainers fix small stuff for you helps us speed up the process of merging your PR, so if some of your systems warrant further care, be sure to let us know (preferably with a code comment).
Make sure to only mark your PR as "Ready to review" when it is. If you still want to do major changes, you can keep a draft PR open until then.
What
The config is accessed quite often and using a hash map for each one of these accesses adds up over time. This isn't suuper bad, but it is bad enough to the point where it does show up in profiles occasionally and the fix is quite easy. Using an
EnumMap
instead of a regular map is already a bit of a performance boost, but sinceSkyhanniMod.feature
is used very often, I also added a bit of kotlin reflection to automatically set a field whenever it is loaded. Thanks to kotlins property reflection syntax this is fairly easy to use and extend, as well as type checked during compilation.Going further
Almost every feature right now accesses the config multiple times per tick, sometimes per frame. While those accesses are just a few chained
GETFIELD
s, this could probably be improved. Config changes are rare and config changes within the same tick are something that we should simply not consider. The infrastructure for this does not exist right now, but one could imagine a future where moulconfigs properties are used extensively to reduce each config access down to at most twoGETFIELD
s each method call. Is this our future or one of our many divergent timelines? Is this future desirable? Is it worth the effort? I don't have the answer. I just know that performance can be found even in the most unlikely of places if you just open your eyes.Changelog Improvements
Changelog Technical Details
.gitignore
so that subdirectories of the.idea
folder can be manually unignored. - nea