mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Apply Purpur Paper patch
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Raneri <kevin.raneri@gmail.com>
|
||||
Date: Wed, 10 Nov 2021 00:37:03 -0500
|
||||
Subject: [PATCH] Pufferfish: Optimize mob spawning
|
||||
|
||||
Original license: GPL v3
|
||||
Original project: https://github.com/pufferfish-gg/Pufferfish
|
||||
|
||||
Co-authored-by: booky10 <boooky10@gmail.com>
|
||||
Co-authored-by: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
|
||||
This patch aims to reduce the main-thread impact of mob spawning by
|
||||
offloading as much work as possible to other threads. It is possible for
|
||||
inconsistencies to come up, but when they happen they never interfere
|
||||
with the server's operation (they don't produce errors), and side
|
||||
effects are limited to more or less mobs being spawned in any particular
|
||||
tick.
|
||||
|
||||
It is possible to disable this optimization if it is not required or if
|
||||
it interferes with any plugins. On servers with thousands of entities,
|
||||
this can result in performance gains of up to 15%, which is significant
|
||||
and, in my opinion, worth the low risk of minor mob-spawning-related
|
||||
inconsistencies.
|
||||
|
||||
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java b/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
|
||||
index c21e00812f1aaa1279834a0562d360d6b89e146c..4ae478c04ef44c91408a7f3f0405291f91794873 100644
|
||||
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
|
||||
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/IteratorSafeOrderedReferenceSet.java
|
||||
@@ -10,7 +10,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
public static final int ITERATOR_FLAG_SEE_ADDITIONS = 1 << 0;
|
||||
|
||||
private final Reference2IntLinkedOpenHashMap<E> indexMap;
|
||||
- private int firstInvalidIndex = -1;
|
||||
+ private volatile int firstInvalidIndex = -1; // Leaf - Async mob spawning - volatile
|
||||
|
||||
/* list impl */
|
||||
private E[] listElements;
|
||||
@@ -18,7 +18,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
|
||||
private final double maxFragFactor;
|
||||
|
||||
- private int iteratorCount;
|
||||
+ private final java.util.concurrent.atomic.AtomicInteger iteratorCount = new java.util.concurrent.atomic.AtomicInteger(); // Pufferfish - async mob spawning
|
||||
|
||||
public IteratorSafeOrderedReferenceSet() {
|
||||
this(16, 0.75f, 16, 0.2);
|
||||
@@ -79,7 +79,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
}
|
||||
|
||||
public int createRawIterator() {
|
||||
- ++this.iteratorCount;
|
||||
+ this.iteratorCount.incrementAndGet(); // Pufferfish - async mob spawning
|
||||
if (this.indexMap.isEmpty()) {
|
||||
return -1;
|
||||
} else {
|
||||
@@ -100,7 +100,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
}
|
||||
|
||||
public void finishRawIterator() {
|
||||
- if (--this.iteratorCount == 0) {
|
||||
+ if (this.iteratorCount.decrementAndGet() == 0) { // Pufferfish - async mob spawning
|
||||
if (this.getFragFactor() >= this.maxFragFactor) {
|
||||
this.defrag();
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.listElements[index] = null;
|
||||
- if (this.iteratorCount == 0 && this.getFragFactor() >= this.maxFragFactor) {
|
||||
+ if (this.iteratorCount.get() == 0 && this.getFragFactor() >= this.maxFragFactor) { // Pufferfish - async mob spawning
|
||||
this.defrag();
|
||||
}
|
||||
//this.check();
|
||||
@@ -219,7 +219,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
||||
}
|
||||
|
||||
public IteratorSafeOrderedReferenceSet.Iterator<E> iterator(final int flags) {
|
||||
- ++this.iteratorCount;
|
||||
+ this.iteratorCount.incrementAndGet(); // Pufferfish - async mob spawning
|
||||
return new BaseIterator<>(this, true, (flags & ITERATOR_FLAG_SEE_ADDITIONS) != 0 ? Integer.MAX_VALUE : this.listSize);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,50 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: hayanesuru <mc@jvavav.com>
|
||||
Date: Fri, 28 Mar 2025 21:19:19 +0800
|
||||
Subject: [PATCH] Async playerdata saving
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
index f2d87c12dd19210ce7e2147fada5c10191008632..0cc6b6c597ca8c955b246764de637be4c25bfb40 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
@@ -207,7 +207,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
}
|
||||
|
||||
private CompoundTag getData() {
|
||||
- return this.storage.load(this.profile.getName(), this.profile.getId().toString()).orElse(null);
|
||||
+ return this.storage.load(this.profile.getName(), this.profile.getId().toString(), this.profile.getId()).orElse(null); // Leaf - Async playerdata saving
|
||||
}
|
||||
|
||||
private CompoundTag getBukkitData() {
|
||||
@@ -813,6 +813,17 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
* @param compoundTag
|
||||
*/
|
||||
private void save(CompoundTag compoundTag) {
|
||||
+ // Leaf start - Async playerdata saving
|
||||
+ synchronized (server.console.playerDataStorage) {
|
||||
+ while (server.console.playerDataStorage.savingQueue.contains(getUniqueId())) {
|
||||
+ try {
|
||||
+ Thread.sleep(1L);
|
||||
+ } catch (InterruptedException ignored) {
|
||||
+ }
|
||||
+ }
|
||||
+ server.console.playerDataStorage.savingQueue.add(getUniqueId());
|
||||
+ }
|
||||
+ // Leaf end - Async playerdata saving
|
||||
File playerDir = server.console.playerDataStorage.getPlayerDir();
|
||||
try {
|
||||
File tempFile = File.createTempFile(this.getUniqueId()+"-", ".dat", playerDir);
|
||||
@@ -822,6 +833,12 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
net.minecraft.Util.safeReplaceFile(playerDataFile.toPath(), tempFile.toPath(), playerDataFileOld.toPath());
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
+ // Leaf start - Async playerdata saving
|
||||
+ } finally {
|
||||
+ synchronized (server.console.playerDataStorage) {
|
||||
+ server.console.playerDataStorage.savingQueue.remove(getUniqueId());
|
||||
+ }
|
||||
+ // Leaf end - Async playerdata saving
|
||||
}
|
||||
}
|
||||
// Purpur end - OfflinePlayer API
|
||||
Reference in New Issue
Block a user