OneLiteFeatherNET / Microtus

Up to date Minestom fork caring about community, code quality & stability
https://wiki.microtus.dev
Other
9 stars 3 forks source link

Improve BlockFace usage to avoid unnecessary object creation #74

Closed theEvilReaper closed 2 months ago

theEvilReaper commented 2 months ago

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.

sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarCloud