Skip to content

Commit

Permalink
Optimize layer iteration to prevent performance overhead. (#3022)
Browse files Browse the repository at this point in the history
* Optimize layer iteration to prevent performance overhead.

Adjusted the layer iteration logic in the Region class to use the minimum and maximum Y-values from the chunk. This prevents unnecessary iterations when getMinimumY or getMaximumY returns extreme values, improving performance efficiency.

* Optimize layer iteration logic in Region class.

Refactored the loop to reduce repeated evaluations by storing pre-calculated min and max values for Y coordinates. This change enhances readability and may improve performance by minimizing unnecessary calculations during the iteration process.

* Update variable naming

* Shift bitwise operations to variable initialization
  • Loading branch information
NonSwag authored Dec 15, 2024
1 parent b548219 commit afec252
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
if (tx >= min.x() && bx <= max.x() && tz >= min.z() && bz <= max.z()) {
// contains some
boolean processExtra = false;
for (int layer = getMinimumY() >> 4; layer <= getMaximumY() >> 4; layer++) {
final int minLayer = Math.max(getMinimumY(), chunk.getMinY()) >> 4;
final int maxLayer = Math.min(getMaximumY(), chunk.getMaxY()) >> 4;
for (int layer = minLayer; layer <= maxLayer; layer++) {
if (!set.hasSection(layer)) {
continue;
}
Expand Down Expand Up @@ -457,7 +459,9 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set, boolean
if (tx >= min.x() && bx <= max.x() && tz >= min.z() && bz <= max.z()) {
// contains some
boolean processExtra = false;
for (int layer = getMinimumY() >> 4; layer <= getMaximumY() >> 4; layer++) {
final int minLayer = Math.max(getMinimumY(), chunk.getMinY()) >> 4;
final int maxLayer = Math.min(getMaximumY(), chunk.getMaxY()) >> 4;
for (int layer = minLayer; layer <= maxLayer; layer++) {
int by = layer << 4;
int ty = by + 15;
if (containsEntireCuboid(bx, tx, by, ty, bz, tz)) {
Expand Down

0 comments on commit afec252

Please sign in to comment.