aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0437-Optimize-ServerLevels-chunk-level-checking-methods.patch
blob: 256818f9783f89f727f2a5e9b9d27968ada0914f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 16 Apr 2020 16:13:59 -0700
Subject: [PATCH] Optimize ServerLevels chunk level checking methods

These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.

diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 3fea7315ed3caf7363dd9349f8e977282dfa4c07..00d5060e2a81a7c5fe32f8b9ed8334ff844a70f5 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2139,15 +2139,18 @@ public class ServerLevel extends Level implements WorldGenLevel {
     }
 
     private boolean isPositionTickingWithEntitiesLoaded(long chunkPos) {
-        return this.areEntitiesLoaded(chunkPos) && this.chunkSource.isPositionTicking(chunkPos);
+        // Paper start - optimize is ticking ready type functions
+        ChunkHolder chunkHolder = this.chunkSource.chunkMap.getVisibleChunkIfPresent(chunkPos);
+        return chunkHolder != null && this.chunkSource.isPositionTicking(chunkPos) && chunkHolder.isTickingReady() && this.areEntitiesLoaded(chunkPos);
+        // Paper end
     }
 
     public boolean isPositionEntityTicking(BlockPos pos) {
-        return this.entityManager.isPositionTicking(pos);
+        return this.entityManager.isPositionTicking(ChunkPos.asLong(pos)); // Paper
     }
 
     public boolean isPositionEntityTicking(ChunkPos pos) {
-        return this.entityManager.isPositionTicking(pos);
+        return this.entityManager.isPositionTicking(pos.toLong()); // Paper
     }
 
     private final class EntityCallbacks implements LevelCallback<Entity> {
diff --git a/src/main/java/net/minecraft/world/level/ChunkPos.java b/src/main/java/net/minecraft/world/level/ChunkPos.java
index 4c5f8a103b550a681178926096d5f758654c61a7..d2952a1a84ae7326e2d4a1f19497db8f978e4688 100644
--- a/src/main/java/net/minecraft/world/level/ChunkPos.java
+++ b/src/main/java/net/minecraft/world/level/ChunkPos.java
@@ -50,7 +50,7 @@ public class ChunkPos {
     }
 
     public static long asLong(BlockPos pos) {
-        return asLong(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
+        return (((long)pos.getX() >> 4) & 4294967295L) | ((((long)pos.getZ() >> 4) & 4294967295L) << 32); // Paper - inline
     }
 
     public static int getX(long pos) {
diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
index e19f5b2c8f485d596a64d5d96e75fa1f4a8255b5..ccafd28e3dc9a03f310eb5bdde85fcb277ef5116 100644
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
@@ -383,6 +383,11 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
     public LevelEntityGetter<T> getEntityGetter() {
         return this.entityGetter;
     }
+    // Paper start
+    public final boolean isPositionTicking(long position) {
+        return this.chunkVisibility.get(position).isTicking();
+    }
+    // Paper end
 
     public boolean isPositionTicking(BlockPos pos) {
         return ((Visibility) this.chunkVisibility.get(ChunkPos.asLong(pos))).isTicking();