-
Notifications
You must be signed in to change notification settings - Fork 110
/
0033-Reduce-entity-allocations.patch
48 lines (41 loc) · 2.71 KB
/
0033-Reduce-entity-allocations.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul <paul@technove.co>
Date: Fri, 2 Jul 2021 18:25:18 -0500
Subject: [PATCH] Reduce entity allocations
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index f974ef82e58378d9d50d56c1877a06f1574315ae..7a408bafbef2c78e3b17b390881be9e5948147ab 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -426,6 +426,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
public boolean fixedPose = false; // Paper - Expand Pose API
public boolean activatedPriorityReset = false; // Pufferfish - DAB
public int activatedPriority = gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio; // Pufferfish - DAB (golf score)
+ public final BlockPos.MutableBlockPos cachedBlockPos = new BlockPos.MutableBlockPos(); // Pufferfish - reduce entity allocations
public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
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 897d7632ecfea40890433474870dd7a5e534d8ab..683c9693754d1a87b7e8fccc757a0d0963351f60 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; // Pufferfish
public AttributeMap(AttributeSupplier defaultAttributes) {
this.supplier = defaultAttributes;
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute); // Pufferfish
}
private void onAttributeModified(AttributeInstance instance) {
@@ -45,11 +47,10 @@ public class AttributeMap {
}).collect(Collectors.toList());
}
+
@Nullable
public AttributeInstance getInstance(Attribute attribute) {
- return this.attributes.computeIfAbsent(attribute, (attributex) -> {
- return this.supplier.createInstance(this::onAttributeModified, attributex);
- });
+ return this.attributes.computeIfAbsent(attribute, this.createInstance); // Pufferfish - cache lambda, as for some reason java allocates it anyways
}
@Nullable