mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
72 lines
3.7 KiB
Diff
72 lines
3.7 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/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 6bac5eb6534b6f5c47a136afa17a3dd7b2bc1577..91d87917ce7b693c4cc55a5e9c98320b4e7a5ef9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -417,6 +417,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
return this.originWorld;
|
|
}
|
|
// Paper end
|
|
+ // public final BlockPos.MutableBlockPos cachedBlockPos = new BlockPos.MutableBlockPos(); // Leaves - used where needed ?
|
|
+
|
|
public float getBukkitYaw() {
|
|
return this.yRot;
|
|
}
|
|
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 dd1102d5291ef6f18e82400a6d8a0a376cc071e9..53c094c8a674b2842009727569e7e1f6ac6510b7 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 Map<Attribute, AttributeInstance> attributes = Maps.newHashMap();
|
|
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
|
|
private final AttributeSupplier supplier;
|
|
+ private final java.util.function.Function<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) {
|
|
@@ -47,9 +49,15 @@ public class AttributeMap {
|
|
|
|
@Nullable
|
|
public AttributeInstance getInstance(Attribute attribute) {
|
|
- return this.attributes.computeIfAbsent(attribute, (attributex) -> {
|
|
- return this.supplier.createInstance(this::onAttributeModified, attributex);
|
|
- });
|
|
+ // Leaves start - cache lambda, as for some reason java allocates it anyways
|
|
+ if (top.leavesmc.leaves.LeavesConfig.reduceEntityAllocations) {
|
|
+ return this.attributes.computeIfAbsent(attribute, this.createInstance);
|
|
+ } else {
|
|
+ return this.attributes.computeIfAbsent(attribute, (attributex) -> {
|
|
+ return this.supplier.createInstance(this::onAttributeModified, attributex);
|
|
+ });
|
|
+ }
|
|
+ // Leaves end - cache lambda, as for some reason java allocates it anyways
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
index 1335959fc27da3e53ea845dff83fcac0b3a1e873..6227a02006c98fe93f500f2a192aec0ff77a8187 100644
|
|
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
@@ -326,6 +326,11 @@ public final class LeavesConfig {
|
|
skipCloneLootParameters = getBoolean("settings.performance.skip-clone-loot-parameters", skipCloneLootParameters);
|
|
}
|
|
|
|
+ public static boolean reduceEntityAllocations = true;
|
|
+ private static void reduceEntityAllocations() {
|
|
+ reduceEntityAllocations = getBoolean("settings.performance.reduce-entity-allocations", reduceEntityAllocations);
|
|
+ }
|
|
+
|
|
public static final class WorldConfig {
|
|
|
|
public final String worldName;
|