From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Tue, 17 Sep 2024 02:35:13 -0400 Subject: [PATCH] Replace Entity active effects map with optimized collection Dreeam TODO: check this diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index 2539f688102a3c9c10ddeff39f3562668e9010be..d44e48719fcf51f6d425b9c18835ad44339177df 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -199,6 +199,10 @@ public abstract class LivingEntity extends Entity implements Attackable { public static final String ATTRIBUTES_FIELD = "attributes"; private final AttributeMap attributes; public CombatTracker combatTracker = new CombatTracker(this); + // Need to figure out the difference of mem access pattern between hash map and obj2obj hash map (separate chaining vs open addressing) + // Benchmark is needed for get calls for this active effects map. + // Also need to check whether call from out of main using bukkit api + //public final Map, MobEffectInstance> activeEffects = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(0); // Leaf - Replace Entity active effects map with optimized collection public final Map, MobEffectInstance> activeEffects = Maps.newHashMap(); private final NonNullList lastHandItemStacks; private final NonNullList lastArmorItemStacks; @@ -1011,8 +1015,9 @@ public abstract class LivingEntity extends Entity implements Attackable { private void updateSynchronizedMobEffectParticles() { // Leaf start - Remove stream in entity visible effects filter List list = new ArrayList<>(); + final Collection effectsValues = this.activeEffects.values(); // Leaf - Replace Entity active effects map with optimized collection - for (MobEffectInstance effect : this.activeEffects.values()) { + for (MobEffectInstance effect : effectsValues) { // Leaf - Replace Entity active effects map with optimized collection if (effect.isVisible()) { list.add(effect.getParticleOptions()); } @@ -1020,7 +1025,7 @@ public abstract class LivingEntity extends Entity implements Attackable { // Leaf end - Remove stream in entity visible effects filter this.entityData.set(LivingEntity.DATA_EFFECT_PARTICLES, list); - this.entityData.set(LivingEntity.DATA_EFFECT_AMBIENCE_ID, LivingEntity.areAllEffectsAmbient(this.activeEffects.values())); + this.entityData.set(LivingEntity.DATA_EFFECT_AMBIENCE_ID, LivingEntity.areAllEffectsAmbient(effectsValues)); // Leaf - Replace Entity active effects map with optimized collection } private void updateGlowingStatus() {