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.
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.