Improve BlockFace usage to avoid unnecessary object creation#74
Merged
TheMeinerLP merged 2 commits intomasterfrom Sep 14, 2024
Merged
Improve BlockFace usage to avoid unnecessary object creation#74TheMeinerLP merged 2 commits intomasterfrom
TheMeinerLP merged 2 commits intomasterfrom
Conversation
|
TheMeinerLP
requested changes
Sep 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


The
BlockFaceenumeration defines all possible faces a block can have, regardless of whether each face is used by a particular block. However, the usage of the .values method can be optimized. In Java, each time this method is called, a new array reference containing all enumeration entries is created, even though the entries themselves are the same. This can be avoided by caching the result of the method and providing a getter for the cached array. This way, the project can use the cached result without generating new references each time.While this change may seem like a micro-optimization, it has a positive impact on performance. By using a performance profiler like YourKit or the profiler in IntelliJ, you can observe that in some cases, execution time is reduced compared to before the changes were applied. It is also worth noting that the
.valuesmethod is frequently used in light calculations, which are generally heavy operations. In this specific case, the optimization helps reduce execution time slightly.