mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
--------- Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com> Co-authored-by: Fortern <blueten.ki@gmail.com> Co-authored-by: MC_XiaoHei <xor7xiaohei@gmail.com> Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com> Co-authored-by: MC_XiaoHei <xiaohei.xor7@outlook.com>
39 lines
2.2 KiB
Diff
39 lines
2.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Wed, 17 Aug 2022 10:48:18 +0800
|
|
Subject: [PATCH] Reduce entity allocations
|
|
|
|
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
index bed9b564c493cd84bf53fc49368fda736f3fbc2b..69ec8e21c96e26bafedcdd979fc9d050b1f3846f 100644
|
|
--- a/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
+++ b/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
@@ -18,9 +18,11 @@ public class AttributeMap {
|
|
private final Set<AttributeInstance> attributesToSync = new ObjectOpenHashSet<>();
|
|
private final Set<AttributeInstance> attributesToUpdate = new ObjectOpenHashSet<>();
|
|
private final AttributeSupplier supplier;
|
|
+ private final java.util.function.Function<Holder<Attribute>, AttributeInstance> createInstance; // Leaves - reduce entity allocations
|
|
|
|
public AttributeMap(AttributeSupplier supplier) {
|
|
this.supplier = supplier;
|
|
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute);
|
|
}
|
|
|
|
private void onAttributeModified(AttributeInstance instance) {
|
|
@@ -44,7 +46,13 @@ public class AttributeMap {
|
|
|
|
@Nullable
|
|
public AttributeInstance getInstance(Holder<Attribute> attribute) {
|
|
- return this.attributes.computeIfAbsent(attribute, holder -> this.supplier.createInstance(this::onAttributeModified, (Holder<Attribute>)holder));
|
|
+ // Leaves start - cache lambda, as for some reason java allocates it anyways
|
|
+ if (org.leavesmc.leaves.LeavesConfig.performance.reduceEntityAllocations) {
|
|
+ return this.attributes.computeIfAbsent(attribute, this.createInstance);
|
|
+ } else {
|
|
+ return this.attributes.computeIfAbsent(attribute, holder -> this.supplier.createInstance(this::onAttributeModified, (Holder<Attribute>)holder));
|
|
+ }
|
|
+ // Leaves end - cache lambda, as for some reason java allocates it anyways
|
|
}
|
|
|
|
public boolean hasAttribute(Holder<Attribute> attribute) {
|