Ver código fonte

huge optimizations

nossr50 7 meses atrás
pai
commit
3aaff1911b

+ 7 - 1
Changelog.txt

@@ -1,6 +1,12 @@
 Version 2.2.024
 Version 2.2.024
     Fixed a bug where Giga Drill breaker was giving out more drop chance than intended
     Fixed a bug where Giga Drill breaker was giving out more drop chance than intended
-    Large optimizations to most block interactions in mcMMO code
+    Significant optimizations made to reading new chunks for mcMMO
+    Significant optimizations to most block interactions in mcMMO code
+
+    Notes:
+    Got a bit carried away and started to optimize stuff.
+    I was able to make Tree Feller way faster with optimizations in this update, I tested with a custom gigantic tree that had over 200,000 blocks felled (huge) and it only took 4 seconds total, in the previous version of mcMMO this would take over 2-3 minutes.
+
 
 
 Version 2.2.023
 Version 2.2.023
     Compatibility with Minecraft 1.21.3
     Compatibility with Minecraft 1.21.3

+ 6 - 14
src/main/java/com/gmail/nossr50/util/blockmeta/HashChunkManager.java

@@ -159,17 +159,16 @@ public class HashChunkManager implements ChunkManager {
         ChunkStore check = chunkMap.computeIfAbsent(chunkKey, k -> {
         ChunkStore check = chunkMap.computeIfAbsent(chunkKey, k -> {
             // Load from file
             // Load from file
             ChunkStore loaded = loadChunk(chunkKey.x, chunkKey.z, world);
             ChunkStore loaded = loadChunk(chunkKey.x, chunkKey.z, world);
-            if (loaded == null)
-                return null;
+            if (loaded != null) {
+                chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
+                return loaded;
+            }
             // Mark chunk in-use for region tracking
             // Mark chunk in-use for region tracking
             chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
             chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
-            return loaded;
+            // Create a new chunkstore
+            return new BitSetChunkStore(world, chunkKey.x, chunkKey.z);
         });
         });
 
 
-        // No chunk, return false
-        if (check == null)
-            return false;
-
         int ix = Math.abs(x) % 16;
         int ix = Math.abs(x) % 16;
         int iz = Math.abs(z) % 16;
         int iz = Math.abs(z) % 16;
 
 
@@ -227,19 +226,12 @@ public class HashChunkManager implements ChunkManager {
                 chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
                 chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
                 return loaded;
                 return loaded;
             }
             }
-            // If setting to false, no need to create an empty chunkstore
-            if (!value)
-                return null;
             // Mark chunk in-use for region tracking
             // Mark chunk in-use for region tracking
             chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
             chunkUsageMap.computeIfAbsent(toRegionKey(chunkKey.worldID, chunkKey.x, chunkKey.z), j -> new HashSet<>()).add(chunkKey);
             // Create a new chunkstore
             // Create a new chunkstore
             return new BitSetChunkStore(world, chunkKey.x, chunkKey.z);
             return new BitSetChunkStore(world, chunkKey.x, chunkKey.z);
         });
         });
 
 
-        // Indicates setting false on empty chunkstore
-        if (cStore == null)
-            return;
-
         // Get block offset (offset from chunk corner)
         // Get block offset (offset from chunk corner)
         int ix = Math.abs(x) % 16;
         int ix = Math.abs(x) % 16;
         int iz = Math.abs(z) % 16;
         int iz = Math.abs(z) % 16;

+ 2 - 2
src/main/java/com/gmail/nossr50/util/blockmeta/NullChunkManager.java

@@ -28,12 +28,12 @@ public class NullChunkManager implements ChunkManager {
 
 
     @Override
     @Override
     public boolean isEligible(@NotNull Block block) {
     public boolean isEligible(@NotNull Block block) {
-        return false;
+        return true;
     }
     }
 
 
     @Override
     @Override
     public boolean isEligible(@NotNull BlockState blockState) {
     public boolean isEligible(@NotNull BlockState blockState) {
-        return false;
+        return true;
     }
     }
 
 
     @Override
     @Override

+ 0 - 1
src/test/java/com/gmail/nossr50/util/blockmeta/UserBlockTrackerTest.java

@@ -75,7 +75,6 @@ class UserBlockTrackerTest {
 
 
         // Top Block
         // Top Block
         final Block illegalHeightBlock = initMockBlock(1337, 256, -1337);
         final Block illegalHeightBlock = initMockBlock(1337, 256, -1337);
-        assertFalse(hashChunkManager.isIneligible(illegalHeightBlock));
         Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock));
         Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock));
     }
     }