9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 11:59:24 +00:00
Files
Leaf/patches/server/0088-Tracking-Optimize-Use-thread-safe-Collection.patch

65 lines
4.8 KiB
Diff

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: Use thread-safe Collection
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index b0a6d5951b80a056c7f070188918cac50b0fe9ca..c564136c9304b0cf9aef22dba2fc3a53a1d7f30b 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -241,7 +241,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
public final io.papermc.paper.util.player.NearbyPlayers nearbyPlayers;
// Paper end
// Paper start - optimise chunk tick iteration
- public final it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<ChunkHolder> needsChangeBroadcasting = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ public final Set<ChunkHolder> needsChangeBroadcasting = Sets.newConcurrentHashSet(); // Leaf - Use thread-safe collection
public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerMobSpawnMap = new gg.pufferfish.pufferfish.util.AsyncPlayerAreaMap(this.pooledLinkedPlayerHashSets); // Pufferfish
// Paper end - optimise chunk tick iteration
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index f1718d57dab1e81c906874f51986868d897f87f1..0e20bf94822dc0f56cfce3e3b4a54235f96d1ef9 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -646,7 +646,7 @@ public class ServerChunkCache extends ChunkSource {
// Paper - optimise chunk tick iteration
// Paper start - optimise chunk tick iteration
if (!this.chunkMap.needsChangeBroadcasting.isEmpty()) {
- it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<ChunkHolder> copy = this.chunkMap.needsChangeBroadcasting.clone();
+ List<ChunkHolder> copy = new java.util.ArrayList<>(this.chunkMap.needsChangeBroadcasting); // Leaf - Use thread-safe collection
this.chunkMap.needsChangeBroadcasting.clear();
for (ChunkHolder holder : copy) {
holder.broadcastChanges(holder.getFullChunkNowUnchecked()); // LevelChunks are NEVER unloaded
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 23226bc990044e33471de6bc9610c2c5ee707f3e..f45cf9c7c2d67fafee6bb5409ffc975dc0d3b133 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -426,7 +426,7 @@ public class ServerEntity {
if (!set.isEmpty()) {
// Leaf start - petal - sync
- final Set<AttributeInstance> copy = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(set);
+ final Set<AttributeInstance> copy = com.google.common.collect.Sets.newConcurrentHashSet(set);
((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> {
// CraftBukkit start - Send scaled max health
if (this.entity instanceof ServerPlayer) {
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 94082358b0dd573e09e61b167af2a54f8aa4bb2a..97a9fa03011dd8f524319924d07cd98d93c88f64 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,10 +21,12 @@ import org.slf4j.Logger;
public class AttributeMap {
private static final Logger LOGGER = LogUtils.getLogger();
+ // Leaf start - Use thread-safe collection
// Gale start - Lithium - replace AI attributes with optimized collections
- private final Map<Attribute, AttributeInstance> attributes = new Reference2ReferenceOpenHashMap<>(0);
- private final Set<AttributeInstance> dirtyAttributes = new ReferenceOpenHashSet<>(0);
+ private final Map<Attribute, AttributeInstance> attributes = com.google.common.collect.Maps.newConcurrentMap();
+ private final Set<AttributeInstance> dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet();
// Gale end - Lithium - replace AI attributes with optimized collections
+ // Leaf end - Use thread-safe collection
private final AttributeSupplier supplier;
private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Gale - Airplane - reduce entity allocations
private final net.minecraft.world.entity.LivingEntity entity; // Purpur