mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-24 01:19:19 +00:00
Update Paper
This commit is contained in:
38
patches/server/0026-Reduce-entity-allocations.patch
Normal file
38
patches/server/0026-Reduce-entity-allocations.patch
Normal file
@@ -0,0 +1,38 @@
|
||||
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/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
||||
index 69992ebc999ea3ff9e47e4e049bcc514c01150ca..2118ad41e94e8f5e5fac50286ceb24ab70db88f2 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
|
||||
@@ -23,9 +23,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 defaultAttributes) {
|
||||
this.supplier = defaultAttributes;
|
||||
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute);
|
||||
}
|
||||
|
||||
private void onAttributeModified(AttributeInstance instance) {
|
||||
@@ -49,7 +51,13 @@ public class AttributeMap {
|
||||
|
||||
@Nullable
|
||||
public AttributeInstance getInstance(Holder<Attribute> attribute) {
|
||||
- return this.attributes.computeIfAbsent(attribute, attributex -> this.supplier.createInstance(this::onAttributeModified, attributex));
|
||||
+ // Leaves start - cache lambda, as for some reason java allocates it anyways
|
||||
+ if (org.leavesmc.leaves.LeavesConfig.reduceEntityAllocations) {
|
||||
+ return this.attributes.computeIfAbsent(attribute, this.createInstance);
|
||||
+ } else {
|
||||
+ return this.attributes.computeIfAbsent(attribute, attributex -> this.supplier.createInstance(this::onAttributeModified, attributex));
|
||||
+ }
|
||||
+ // Leaves end - cache lambda, as for some reason java allocates it anyways
|
||||
}
|
||||
|
||||
public boolean hasAttribute(Holder<Attribute> attribute) {
|
||||
Reference in New Issue
Block a user