mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 02:19:19 +00:00
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2 since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList. Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2 lazy handles filter condition on iteration, so much better.
75 lines
5.0 KiB
Diff
75 lines
5.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Mon, 14 Apr 2025 14:36:57 +0200
|
|
Subject: [PATCH] Optimize ThreadedTicketLevelPropagator
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
|
|
index 310a8f80debadd64c2d962ebf83b7d0505ce6e42..878f8beb769e87f1de70e7be963e88678a89dd0a 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
|
|
@@ -998,6 +998,7 @@ public abstract class ThreadedTicketLevelPropagator {
|
|
final int decodeOffsetZ = -this.encodeOffsetZ;
|
|
final int encodeOffset = this.coordinateOffset;
|
|
final int sectionOffset = this.sectionIndexOffset;
|
|
+ final Section[] sectionsArray = this.sections; // Leaf - Optimize ThreadedTicketLevelPropagator
|
|
|
|
final Long2ByteLinkedOpenHashMap updatedPositions = this.updatedPositions;
|
|
|
|
@@ -1012,13 +1013,27 @@ public abstract class ThreadedTicketLevelPropagator {
|
|
int propagateDirectionBitset = (int)(queueValue >>> (COORDINATE_BITS + COORDINATE_BITS + LEVEL_BITS)) & ((1 << 16) - 1);
|
|
|
|
if ((queueValue & FLAG_RECHECK_LEVEL) != 0L) {
|
|
- if (this.getLevel(posX, posZ) != propagatedLevel) {
|
|
+ // Leaf start - Optimize ThreadedTicketLevelPropagator
|
|
+ final int sectionX = posX >> SECTION_SHIFT;
|
|
+ final int sectionZ = posZ >> SECTION_SHIFT;
|
|
+ final Section section = sectionsArray[sectionX + (sectionZ * SECTION_CACHE_WIDTH) + sectionOffset];
|
|
+ final int localIdx = (posX & (SECTION_SIZE - 1)) | ((posZ & (SECTION_SIZE - 1)) << SECTION_SHIFT);
|
|
+ if ((section.levels[localIdx] & 0xFF) != propagatedLevel) {
|
|
+ // Leaf end - Optimize ThreadedTicketLevelPropagator
|
|
// not at the level we expect, so something changed.
|
|
continue;
|
|
}
|
|
} else if ((queueValue & FLAG_WRITE_LEVEL) != 0L) {
|
|
// these are used to restore sources after a propagation decrease
|
|
- this.setLevel(posX, posZ, propagatedLevel);
|
|
+ // Leaf start - Optimize ThreadedTicketLevelPropagator
|
|
+ final int sectionX = posX >> SECTION_SHIFT;
|
|
+ final int sectionZ = posZ >> SECTION_SHIFT;
|
|
+ final Section section = sectionsArray[sectionX + (sectionZ * SECTION_CACHE_WIDTH) + sectionOffset];
|
|
+ final int localIdx = (posX & (SECTION_SIZE - 1)) | ((posZ & (SECTION_SIZE - 1)) << SECTION_SHIFT);
|
|
+ final short currentLevel = section.levels[localIdx];
|
|
+ section.levels[localIdx] = (short) ((currentLevel & ~0xFF) | (propagatedLevel & 0xFF));
|
|
+ updatedPositions.put(CoordinateUtils.getChunkKey(posX, posZ), (byte) propagatedLevel);
|
|
+ // Leaf end - Optimize ThreadedTicketLevelPropagator
|
|
}
|
|
|
|
// this bitset represents the values that we have not propagated to
|
|
@@ -1093,7 +1108,7 @@ public abstract class ThreadedTicketLevelPropagator {
|
|
currentPropagation ^= (bitsetLine1 | bitsetLine2 | bitsetLine3);
|
|
|
|
// now try to propagate
|
|
- final Section section = this.sections[sectionIndex];
|
|
+ final Section section = sectionsArray[sectionIndex]; // Leaf - Optimize ThreadedTicketLevelPropagator
|
|
|
|
// lower 8 bits are current level, next upper 7 bits are source level, next 1 bit is updated source flag
|
|
final short currentStoredLevel = section.levels[localIndex];
|
|
@@ -1144,6 +1159,7 @@ public abstract class ThreadedTicketLevelPropagator {
|
|
final int decodeOffsetZ = -this.encodeOffsetZ;
|
|
final int encodeOffset = this.coordinateOffset;
|
|
final int sectionOffset = this.sectionIndexOffset;
|
|
+ final Section[] sectionsArray = this.sections; // Leaf - Optimize ThreadedTicketLevelPropagator
|
|
|
|
final Long2ByteLinkedOpenHashMap updatedPositions = this.updatedPositions;
|
|
|
|
@@ -1227,7 +1243,7 @@ public abstract class ThreadedTicketLevelPropagator {
|
|
final long bitsetLine3 = currentPropagation & (7L << (start + (8 + 8)));
|
|
|
|
// now try to propagate
|
|
- final Section section = this.sections[sectionIndex];
|
|
+ final Section section = sectionsArray[sectionIndex]; // Leaf - Optimize ThreadedTicketLevelPropagator
|
|
|
|
// lower 8 bits are current level, next upper 7 bits are source level, next 1 bit is updated source flag
|
|
final short currentStoredLevel = section.levels[localIndex];
|