From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Thu, 23 May 2024 21:28:02 +0800 Subject: [PATCH] Tracking Optimize: Reduce expensive iteration Removed since 1.21, not good, useless diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java index 29780ed86e938ea1f9e6405e5dee84b09abe3ac0..4c23012c07d91b804ed72bfa4ee953dfad7a7a96 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -1173,6 +1173,9 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider return; } // Leaf end - petal + + if (net.minecraft.server.MinecraftServer.getServer().getPlayerList().players.isEmpty()) return; // Leaf - Don't update since the server is empty + for (TrackedEntity tracker : this.entityMap.values()) { // update tracker entry tracker.updatePlayers(tracker.entity.getPlayersInTrackRange()); diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java index d57c6b9d9b37d94829c01f63977ad2caca110dfd..c2db18cbb1230588e6b1783dc51c69ed3ccd2e34 100644 --- a/src/main/java/net/minecraft/server/level/ServerEntity.java +++ b/src/main/java/net/minecraft/server/level/ServerEntity.java @@ -449,7 +449,7 @@ public class ServerEntity { // Leaf end - petal } - set.clear(); + ((LivingEntity) this.entity).getAttributes().clearDirtyAttributes(); // Leaf } } diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java index 9d16bcfb64885d8f23df8effd44f35bb3a0fa2e4..9c06b3f76ca9d4f270399d983f1f31c5152de96d 100644 --- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java +++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java @@ -21,7 +21,7 @@ public class AttributeMap { private static final Logger LOGGER = LogUtils.getLogger(); // Leaf start - Use thread-safe collection private final Map, AttributeInstance> attributes = com.google.common.collect.Maps.newConcurrentMap(); - private final Set dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(); + private Set dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(); // Leaf - no final // Leaf end - Use thread-safe collection private final AttributeSupplier supplier; private final java.util.function.Function, AttributeInstance> createInstance; // Gale - Airplane - reduce entity allocations @@ -49,6 +49,12 @@ public class AttributeMap { return this.dirtyAttributes; } + // Leaf start - Reduce expensive clear() iteration + public void clearDirtyAttributes() { + this.dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(); + } + // Leaf end - Reduce expensive clear() iteration + public Collection getSyncableAttributes() { return this.attributes.values().stream().filter(attribute -> attribute.getAttribute().value().isClientSyncable() && (entity == null || entity.shouldSendAttribute(attribute.getAttribute().value()))).collect(Collectors.toList()); // Purpur }