9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-04 15:41:40 +00:00

Drop patch that causes performance regression

Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
This commit is contained in:
Dreeam
2025-08-04 18:46:50 +08:00
parent 212815e788
commit 9a4efaa230
212 changed files with 94 additions and 86 deletions

View File

@@ -0,0 +1,26 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 22 Mar 2025 00:07:38 +0100
Subject: [PATCH] Optimize addOrUpdateTransientModifier
diff --git a/net/minecraft/world/entity/ai/attributes/AttributeInstance.java b/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
index 7f8eb388308806008805970d4d8ed329440380ee..7f1b670eab23c02fb0f27cfa5ca0d0113794c8eb 100644
--- a/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
+++ b/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
@@ -105,8 +105,13 @@ public class AttributeInstance {
}
public void addOrUpdateTransientModifier(AttributeModifier modifier) {
- AttributeModifier attributeModifier = this.modifierById.put(modifier.id(), modifier);
- if (modifier != attributeModifier) {
+ // Leaf start - Optimize addOrUpdateTransientModifier
+ // First check if we already have the same modifier instance to avoid unnecessary put operations
+ AttributeModifier existingModifier = this.modifierById.get(modifier.id());
+ // Only perform updates if the modifier is new or different
+ if (existingModifier != modifier) {
+ this.modifierById.put(modifier.id(), modifier);
+ // Leaf end - Optimize addOrUpdateTransientModifier
this.getModifiers(modifier.operation()).put(modifier.id(), modifier);
this.setDirty();
}