mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2025-02-02 21:41:25 +01:00
Heavily optimize recipe lookups in CraftingManager
Author is @nkomarn .
This commit is contained in:
parent
5b37c44801
commit
576ab42b68
@ -68,6 +68,7 @@ # Patches
|
||||
| server | Giants AI settings | William Blake Galbreath | |
|
||||
| server | Global Eula file | tr7zw | |
|
||||
| server | Heavily optimize furnance fuel and recipe lookups | tr7zw | |
|
||||
| server | Heavily optimize recipe lookups in CraftingManager | Mykyta Komarn | |
|
||||
| server | Highly optimize VillagePlace filtering | Ivan Pekov | |
|
||||
| server | Illusioners AI settings | William Blake Galbreath | |
|
||||
| server | Implement bed explosion options | William Blake Galbreath | |
|
||||
@ -123,6 +124,7 @@ # Patches
|
||||
| server | Swaps the predicate order of collision | ㄗㄠˋ ㄑㄧˊ | |
|
||||
| server | Timings stuff | William Blake Galbreath | |
|
||||
| server | Tulips change fox type | William Blake Galbreath | |
|
||||
| server | Use GlueList as delegate for NonNullList | Mykyta Komarn | |
|
||||
| server | Use block distance in portal search radius | Patrick Hemmer | |
|
||||
| server | Use faster block collision check for entity suffocation check | Mykyta Komarn | |
|
||||
| server | Use offline uuids if we need to | Ivan Pekov | |
|
||||
|
@ -6,7 +6,7 @@ Subject: [PATCH] Fix recipe crash
|
||||
Caused due to slow streams, was kabooming tps when you were crafting F A S T
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
index 64adf87f2fe9921e49bf7a76170bb9908dfdaf19..de7d5ed8d6260ce5ee4164df29cdaf69f561045c 100644
|
||||
index 64adf87f2fe9921e49bf7a76170bb9908dfdaf19..a707c85f2f6b0177781755decc8bc2e0d1eacd4a 100644
|
||||
--- a/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
+++ b/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
@@ -78,9 +78,15 @@ public class CraftingManager extends ResourceDataJson {
|
||||
@ -14,8 +14,8 @@ index 64adf87f2fe9921e49bf7a76170bb9908dfdaf19..de7d5ed8d6260ce5ee4164df29cdaf69
|
||||
public <C extends IInventory, T extends IRecipe<C>> Optional<T> craft(Recipes<T> recipes, C c0, World world) {
|
||||
// CraftBukkit start
|
||||
+ // Yatopia start - replace stream
|
||||
+ List<IRecipe<C>> collection = new java.util.ArrayList<>(this.b(recipes).values());
|
||||
+ Optional<T> recipe = collection.isEmpty() ? Optional.empty() : recipes.a(collection.get(0), world, c0);
|
||||
+ Collection<IRecipe<C>> collection = this.b(recipes).values();
|
||||
+ Optional<T> recipe = collection.isEmpty() ? Optional.empty() : recipes.a(collection.iterator().next(), world, c0);
|
||||
+ /*
|
||||
Optional<T> recipe = this.b(recipes).values().stream().flatMap((irecipe) -> {
|
||||
return SystemUtils.a(recipes.a(irecipe, world, c0));
|
||||
|
@ -0,0 +1,49 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Mykyta Komarn <nkomarn@hotmail.com>
|
||||
Date: Thu, 1 Oct 2020 06:52:35 -0700
|
||||
Subject: [PATCH] Use GlueList as delegate for NonNullList
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/NonNullList.java b/src/main/java/net/minecraft/server/NonNullList.java
|
||||
index 2d3c406a05b9710d40471aa61c3540dbc971c1e3..52b263fc257e5e8889aa8285331581b7d8142c44 100644
|
||||
--- a/src/main/java/net/minecraft/server/NonNullList.java
|
||||
+++ b/src/main/java/net/minecraft/server/NonNullList.java
|
||||
@@ -10,7 +10,7 @@ import org.apache.commons.lang3.Validate;
|
||||
|
||||
public class NonNullList<E> extends AbstractList<E> {
|
||||
|
||||
- private final List<E> a;
|
||||
+ private final net.yatopia.server.list.GlueList<E> a; // Yatopia
|
||||
private final E b;
|
||||
|
||||
public static <E> NonNullList<E> a() {
|
||||
@@ -22,7 +22,7 @@ public class NonNullList<E> extends AbstractList<E> {
|
||||
Object[] aobject = new Object[i];
|
||||
|
||||
Arrays.fill(aobject, e0);
|
||||
- return new NonNullList<>(Arrays.asList(aobject), e0);
|
||||
+ return new NonNullList<>((List<E>) Arrays.asList(aobject), e0); // Yatopia - decompile fix
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@@ -31,11 +31,18 @@ public class NonNullList<E> extends AbstractList<E> {
|
||||
}
|
||||
|
||||
protected NonNullList() {
|
||||
- this(Lists.newArrayList(), (Object) null);
|
||||
+ this(new net.yatopia.server.list.GlueList<>(), null); // Yatopia - decompile fix & GlueList
|
||||
}
|
||||
|
||||
protected NonNullList(List<E> list, @Nullable E e0) {
|
||||
- this.a = list;
|
||||
+ // Yatopia start
|
||||
+ if (!(list instanceof net.yatopia.server.list.GlueList)) {
|
||||
+ this.a = new net.yatopia.server.list.GlueList<>(list);
|
||||
+ } else {
|
||||
+ this.a = (net.yatopia.server.list.GlueList<E>) list;
|
||||
+ }
|
||||
+ //this.a = list;
|
||||
+ // Yatopia end
|
||||
this.b = e0;
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Mykyta Komarn <nkomarn@hotmail.com>
|
||||
Date: Thu, 1 Oct 2020 06:57:43 -0700
|
||||
Subject: [PATCH] Heavily optimize recipe lookups in CraftingManager
|
||||
|
||||
Recipe lookups are now cached in CraftingManager, which prevent unnecessary ArrayLists being created for every lookup. Additionally, an EMPTY_MAP variable was added to prevent bottlenecks during map creation, since that map is only ever iterated.
|
||||
|
||||
GlueList was also used as a replacement for ArrayList as it is substantially faster.
|
||||
|
||||
These changes knock off an extra ~10ms of tick duration with a sample of ~7,700 running furnaces on a server.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
index a707c85f2f6b0177781755decc8bc2e0d1eacd4a..bd4bc17245d32772aef60e53eae4a572ffc6d1c2 100644
|
||||
--- a/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
+++ b/src/main/java/net/minecraft/server/CraftingManager.java
|
||||
@@ -25,6 +25,10 @@ public class CraftingManager extends ResourceDataJson {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public Map<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> recipes = ImmutableMap.of(); // CraftBukkit
|
||||
private boolean d;
|
||||
+ // Yatopia start
|
||||
+ public static final Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>> EMPTY_MAP = new Object2ObjectLinkedOpenHashMap<>();
|
||||
+ public static final Map<Recipes<?>, List<IRecipe<?>>> CACHE = new Object2ObjectLinkedOpenHashMap<>();
|
||||
+ // Yatopia end
|
||||
|
||||
public CraftingManager() {
|
||||
super(CraftingManager.a, "recipes");
|
||||
@@ -108,19 +112,25 @@ public class CraftingManager extends ResourceDataJson {
|
||||
}
|
||||
|
||||
public <C extends IInventory, T extends IRecipe<C>> List<T> a(Recipes<T> recipes) {
|
||||
+ // Yatopia start - replaced Logic
|
||||
+ return (List) CACHE.computeIfAbsent(recipes, recipes1 -> {
|
||||
+ return new net.yatopia.server.list.GlueList<>(this.b(recipes).values());
|
||||
+ });
|
||||
+ /*
|
||||
List<IRecipe<C>> list = new ArrayList<>();
|
||||
for (IRecipe<C> irecipe : this.b(recipes).values()) {
|
||||
IRecipe<C> ciRecipe = irecipe;
|
||||
list.add(ciRecipe);
|
||||
}
|
||||
return (List) list;
|
||||
+ */ // Yatopia end
|
||||
}
|
||||
|
||||
public <C extends IInventory, T extends IRecipe<C>> List<T> b(Recipes<T> recipes, C c0, World world) {
|
||||
// Yatopia start - WHY?! WHO DID THIS TO YOU!?!
|
||||
Collection<IRecipe<C>> recipeCollection = this.b(recipes).values();
|
||||
if (recipeCollection.isEmpty()) return java.util.Collections.emptyList();
|
||||
- List<T> ret = new java.util.ArrayList<>();
|
||||
+ List<T> ret = new net.yatopia.server.list.GlueList<>();
|
||||
for (IRecipe<C> iRecipe : recipeCollection) recipes.a(iRecipe, world, c0).ifPresent(ret::add);
|
||||
ret.sort(Comparator.comparing((iRecipe) -> iRecipe.getResult().getTranslationKey()));
|
||||
return ret;
|
||||
@@ -134,7 +144,7 @@ public class CraftingManager extends ResourceDataJson {
|
||||
}
|
||||
|
||||
private <C extends IInventory, T extends IRecipe<C>> Map<MinecraftKey, IRecipe<C>> b(Recipes<T> recipes) {
|
||||
- return (Map) this.recipes.getOrDefault(recipes, new Object2ObjectLinkedOpenHashMap<>()); // CraftBukkit
|
||||
+ return (Map) this.recipes.getOrDefault(recipes, EMPTY_MAP); // CraftBukkit // Yatopia
|
||||
}
|
||||
|
||||
public <C extends IInventory, T extends IRecipe<C>> NonNullList<ItemStack> c(Recipes<T> recipes, C c0, World world) {
|
||||
diff --git a/src/main/java/net/minecraft/server/RecipeItemStack.java b/src/main/java/net/minecraft/server/RecipeItemStack.java
|
||||
index 30da7471c3ecc66a61cb9fe1dd58d6d65438c505..27978f7b52c8db02f69fdcb092ffcce4550904d3 100644
|
||||
--- a/src/main/java/net/minecraft/server/RecipeItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/RecipeItemStack.java
|
||||
@@ -32,7 +32,7 @@ public final class RecipeItemStack implements Predicate<ItemStack> {
|
||||
|
||||
public void buildChoices() {
|
||||
if (this.choices == null) {
|
||||
- List<ItemStack> list = new ArrayList<>();
|
||||
+ List<ItemStack> list = new net.yatopia.server.list.GlueList<>(); // Yatopia
|
||||
Set<ItemStack> uniqueValues = new HashSet<>();
|
||||
for (Provider recipeitemstack_provider : this.b) {
|
||||
for (ItemStack itemStack : recipeitemstack_provider.a()) {
|
Loading…
Reference in New Issue
Block a user