Skip to content

Improve BlockFace usage to avoid unnecessary object creation#74

Merged
TheMeinerLP merged 2 commits intomasterfrom
feature/blockFaceUsage
Sep 14, 2024
Merged

Improve BlockFace usage to avoid unnecessary object creation#74
TheMeinerLP merged 2 commits intomasterfrom
feature/blockFaceUsage

Conversation

@theEvilReaper
Copy link

The BlockFace enumeration 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 .values method is frequently used in light calculations, which are generally heavy operations. In this specific case, the optimization helps reduce execution time slightly.

@theEvilReaper theEvilReaper requested a review from a team as a code owner September 13, 2024 09:14
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@TheMeinerLP TheMeinerLP merged commit 3193179 into master Sep 14, 2024
@TheMeinerLP TheMeinerLP deleted the feature/blockFaceUsage branch September 14, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants