From 82a8294625cc62ac8350d16a7f934b225f30fba9 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Fri, 19 Feb 2021 22:51:52 -0800
Subject: [PATCH] Oprimise map impl for tracked players

Reference2BooleanOpenHashMap is going to have
better lookups than HashMap.
---
 .../server/level/ChunkMap.java.patch          | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/paper-server/patches/sources/net/minecraft/server/level/ChunkMap.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ChunkMap.java.patch
index 9dd0a5c14d..fd8783a42d 100644
--- a/paper-server/patches/sources/net/minecraft/server/level/ChunkMap.java.patch
+++ b/paper-server/patches/sources/net/minecraft/server/level/ChunkMap.java.patch
@@ -67,19 +67,20 @@
          this.mainThreadExecutor = mainThreadExecutor;
          ConsecutiveExecutor consecutiveexecutor = new ConsecutiveExecutor(executor, "worldgen");
  
-@@ -198,6 +235,12 @@
-         this.chunksToEagerlySave.add(pos.toLong());
-     }
+@@ -196,7 +233,13 @@
  
+     private void setChunkUnsaved(ChunkPos pos) {
+         this.chunksToEagerlySave.add(pos.toLong());
++    }
++
 +    // Paper start
 +    public int getMobCountNear(final ServerPlayer player, final net.minecraft.world.entity.MobCategory mobCategory) {
 +        return -1;
-+    }
+     }
 +    // Paper end
-+
+ 
      protected ChunkGenerator generator() {
          return this.worldGenContext.generator();
-     }
 @@ -325,7 +368,7 @@
                          throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a");
                      }
@@ -357,8 +358,12 @@
  
          protected ChunkDistanceManager(final Executor workerExecutor, final Executor mainThreadExecutor) {
              super(workerExecutor, mainThreadExecutor);
-@@ -1424,7 +1511,7 @@
-         public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
+@@ -1421,10 +1508,10 @@
+         final Entity entity;
+         private final int range;
+         SectionPos lastSectionPos;
+-        public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
++        public final Set<ServerPlayerConnection> seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl
  
          public TrackedEntity(final Entity entity, final int i, final int j, final boolean flag) {
 -            this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast);