Yatopia/patches/server/0051-Optimize-advancement-loading.patch
Ivan Pekov 7f24790a35
Updated Upstream and Sidestream(s) (Tuinity/EMC/Purpur/AirplaneLite)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
cf37529 Updated Upstream (Paper)

EMC Changes:
27282006 Updated Paper
456edfa4 One more try to fix more chunks on reload

Purpur Changes:
45d5e9a Fix dolphin spit and phantom flames
9e1b8e7 Clean up teleport outside border patch Add sleeping, inventory, and toWorld checks
8428580 [ci-skip] Add 'fast' argument to './purpur jar' to speed up jenkins build time
cea486c Updated Upstream (Paper)
6cd244c Fix infinite furnaces triggering without lava source
a989361 Fix infinite furnaces leaving empty buckets
6cf1672 Add config option for whether Nether Wart farming Villagers should throw extra Nether Warts at other Villagers
07d4056 Add toggle for Zombified Piglin death always counting as a player kill when angry (Zombified Piglin XP farm nerf option)
9935466 Add config option for Cleric Villagers to farm Nether Wart
47a1707 fix typos
6e42ce8 Updated Upstream (Paper)
740b7d2 [ci-skip] Update readme with downloads API info

AirplaneLite Changes:
5526dde Add download link to readme
2020-12-07 10:10:55 +02:00

108 lines
5.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Tue, 6 Oct 2020 15:10:12 +0300
Subject: [PATCH] Optimize advancement loading
Removed some object allocations and reduced loops
diff --git a/src/main/java/net/minecraft/server/Advancement.java b/src/main/java/net/minecraft/server/Advancement.java
index c405047c00d354bbc1449fd2f917b73f980ef1a5..8b31098032dc7a08d201e20c917f27348dd2f437 100644
--- a/src/main/java/net/minecraft/server/Advancement.java
+++ b/src/main/java/net/minecraft/server/Advancement.java
@@ -68,6 +68,7 @@ public class Advancement {
return this.display;
}
+ public final AdvancementRewards getRewards() { return d(); } // Yatopia - OBFHELPER
public AdvancementRewards d() {
return this.rewards;
}
diff --git a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
index c680319e4040be2b60795b22a5e65d6444cc67ed..18e80feae122f9b90e61b66e0f660d15585fe3bb 100644
--- a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
+++ b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
@@ -160,11 +160,16 @@ public class AdvancementDataPlayer {
throw new JsonParseException("Found null for advancements");
}
+ /* // Yatopia start - streams no good
Stream<Entry<MinecraftKey, AdvancementProgress>> stream = map.entrySet().stream().sorted(Comparator.comparing(Entry::getValue));
Iterator iterator = ((List) stream.collect(Collectors.toList())).iterator();
while (iterator.hasNext()) {
Entry<MinecraftKey, AdvancementProgress> entry = (Entry) iterator.next();
+ */
+ Entry<MinecraftKey, AdvancementProgress>[] entries = map.entrySet().toArray(new Entry[0]);
+ java.util.Arrays.sort(entries, Entry.comparingByValue());
+ for (Entry<MinecraftKey, AdvancementProgress> entry : entries) { // Yatopia end
Advancement advancement = advancementdataworld.a((MinecraftKey) entry.getKey());
if (advancement == null) {
@@ -201,11 +206,37 @@ public class AdvancementDataPlayer {
}
}
+ /* // Yatopia start
this.c(advancementdataworld);
this.c();
this.b(advancementdataworld);
+ */
+ loadAdvancements(advancementdataworld);
+ // Yatopia end
}
+ // Yatopia start - reduce overload by post io load of advancements
+ // this combines c(AdvancementDataWorld), c() and b(AdvancementDataWorld) into 1 method
+ // the changes done: loops thru all the advancements only once, does not create an additional list
+ // and does not loop thru the additional list, does not create an additional set when checking for progress and
+ // does not additionally loop thru it
+ private void loadAdvancements(AdvancementDataWorld serverAdvancementManager) {
+ for (Advancement advancement : serverAdvancementManager.getAdvancements()) {
+ if (advancement.getCriteria().isEmpty()) {
+ grantCriteria(advancement, "");
+ advancement.getRewards().a(player); // todo: too lazy to import AdvancementRewards for an obfhelper
+ }
+ AdvancementProgress progress = getProgress(advancement);
+ if (progress.isDone()) {
+ this.j.add(advancement);
+ updateVisibility(advancement);
+ continue; // Do not double check isDone
+ }
+ beginTrackingNoIsDone(advancement, progress);
+ }
+ }
+ // Yatopia end
+
public void b() {
if (org.spigotmc.SpigotConfig.disableAdvancementSaving) return; // Spigot
Map<MinecraftKey, AdvancementProgress> map = Maps.newHashMap();
@@ -330,6 +361,11 @@ public class AdvancementDataPlayer {
AdvancementProgress advancementprogress = this.getProgress(advancement);
if (!advancementprogress.isDone()) {
+ // Yatopia start - beginTrackig with no isDone check
+ beginTrackingNoIsDone(advancement, advancementprogress);
+ }
+ }
+ private void beginTrackingNoIsDone(Advancement advancement, AdvancementProgress advancementprogress) {
Iterator iterator = advancement.getCriteria().entrySet().iterator();
while (iterator.hasNext()) {
@@ -349,7 +385,7 @@ public class AdvancementDataPlayer {
}
}
- }
+ //} // Yatopia end
}
private void d(Advancement advancement) {
@@ -444,6 +480,7 @@ public class AdvancementDataPlayer {
this.data.put(advancement, advancementprogress);
}
+ private final void updateVisibility(Advancement advancement) { e(advancement); } // Yatopia
private void e(Advancement advancement) {
// Paper start
e(advancement, IterationEntryPoint.ROOT);