aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWyatt Childers <[email protected]>2020-07-07 01:25:53 -0400
committerAikar <[email protected]>2020-07-07 01:25:53 -0400
commit48ea17fa19c569a668e92fb80de7b41ea8b06c52 (patch)
tree0392576e0cacf9c9652ab7bba1946aab1232e390
parentbe4d74d9332ce8dc0429a6c84df8ed4190d2a9cd (diff)
downloadPaper-48ea17fa19c569a668e92fb80de7b41ea8b06c52.tar.gz
Paper-48ea17fa19c569a668e92fb80de7b41ea8b06c52.zip
Optimize the advancement data player iteration to be O(N) rather than O(N^2)
-rw-r--r--Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch54
1 files changed, 54 insertions, 0 deletions
diff --git a/Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch b/Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch
new file mode 100644
index 0000000000..2f91d733b6
--- /dev/null
+++ b/Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch
@@ -0,0 +1,54 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Wyatt Childers <[email protected]>
+Date: Sat, 4 Jul 2020 23:07:43 -0400
+Subject: [PATCH] Optimize the advancement data player iteration to be O(N)
+ rather than O(N^2)
+
+
+diff --git a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
+index c41e1384724ab150f43dc43fe2a453c9b1262e48..ac7b6734728f912ab9f02dc417f5924b3725adde 100644
+--- a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
++++ b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
+@@ -436,6 +436,16 @@ public class AdvancementDataPlayer {
+ }
+
+ private void e(Advancement advancement) {
++ // Paper start
++ e(advancement, IterationEntryPoint.ROOT);
++ }
++ private enum IterationEntryPoint {
++ ROOT,
++ ITERATOR,
++ PARENT_OF_ITERATOR
++ }
++ private void e(Advancement advancement, IterationEntryPoint entryPoint) {
++ // Paper end
+ boolean flag = this.f(advancement);
+ boolean flag1 = this.g.contains(advancement);
+
+@@ -451,15 +461,23 @@ public class AdvancementDataPlayer {
+ }
+
+ if (flag != flag1 && advancement.b() != null) {
+- this.e(advancement.b());
++ // Paper start - If we're not coming from an iterator consider this to be a root entry, otherwise
++ // market that we're entering from the parent of an iterator.
++ this.e(advancement.b(), entryPoint == IterationEntryPoint.ITERATOR ? IterationEntryPoint.PARENT_OF_ITERATOR : IterationEntryPoint.ROOT);
+ }
+
++ // If this is true, we've went through a child iteration, entered the parent, processed the parent
++ // and are about to reprocess the children. Stop processing here to prevent O(N^2) processing.
++ if (entryPoint == IterationEntryPoint.PARENT_OF_ITERATOR) {
++ return;
++ } // Paper end
++
+ Iterator iterator = advancement.e().iterator();
+
+ while (iterator.hasNext()) {
+ Advancement advancement1 = (Advancement) iterator.next();
+
+- this.e(advancement1);
++ this.e(advancement1, IterationEntryPoint.ITERATOR); // Paper - Mark this call as being from iteration
+ }
+
+ }