Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Dec 26, 2023
1 parent 78ec2bf commit 22b3025
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] new fork who dis - Rebrand to SparklyPaper and Build Changes


diff --git a/build.gradle.kts b/build.gradle.kts
index b12b5a1e82a5ebf47135a3863a390a45a9d8d8ec..b2e2eb5d6e3e63d13e8c4ca1ea0ebf16735555e7 100644
index 58da26ad2f128ba0b66f86820f60853f4be352f0..f2c2d7af8d3647879702c27e8a0ee62e76afd6e7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -3,6 +3,8 @@ import io.papermc.paperweight.util.*
Expand All @@ -17,10 +17,10 @@ index b12b5a1e82a5ebf47135a3863a390a45a9d8d8ec..b2e2eb5d6e3e63d13e8c4ca1ea0ebf16
id("com.github.johnrengelman.shadow")
}

@@ -27,8 +29,15 @@ repositories {
@@ -13,8 +15,15 @@ configurations.named(log4jPlugins.compileClasspathConfigurationName) {
val alsoShade: Configuration by configurations.creating

dependencies {
extraRuntime(platform("net.kyori:adventure-bom:4.15.0-SNAPSHOT"))
- implementation(project(":paper-api"))
- implementation(project(":paper-mojangapi"))
+ // SparklyPaper start
Expand All @@ -35,7 +35,7 @@ index b12b5a1e82a5ebf47135a3863a390a45a9d8d8ec..b2e2eb5d6e3e63d13e8c4ca1ea0ebf16
// Paper start
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
@@ -78,13 +87,18 @@ tasks.jar {
@@ -64,13 +73,18 @@ tasks.jar {
manifest {
val git = Git(rootProject.layout.projectDirectory.path)
val gitHash = git("rev-parse", "--short=7", "HEAD").getText().trim()
Expand All @@ -56,7 +56,7 @@ index b12b5a1e82a5ebf47135a3863a390a45a9d8d8ec..b2e2eb5d6e3e63d13e8c4ca1ea0ebf16
"Implementation-Vendor" to date, // Paper
"Specification-Title" to "Bukkit",
"Specification-Version" to project.version,
@@ -168,7 +182,7 @@ fun TaskContainer.registerRunTask(
@@ -154,7 +168,7 @@ fun TaskContainer.registerRunTask(
name: String,
block: JavaExec.() -> Unit
): TaskProvider<JavaExec> = register<JavaExec>(name) {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0013-Optimize-canSee-checks.patch
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ This seems stupid, but it does seem that it improves the performance a bit, and
We also create a "canSee" method tailored for "ChunkMap#updatePlayer()", a method without the equals check (the "updatePlayer()" already checks if the entity is the same entity) because the CraftPlayer's `equals()` check is a *bit* expensive compared to only checking the object's identity, and because the identity has already been check, we don't need to check it twice.

diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index caa73632aee15583c6b6ed12a668c8f49b794708..fa4c8a52a57775ef8f23e48e57b76ff7abc370c0 100644
index d9cd497bc1b654030ff1a597f038b6a881df9f6b..5c70baf0113004e5c5cbc2fd6a6d34c75cf65217 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1436,7 +1436,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1435,7 +1435,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// Paper end - check Y

// CraftBukkit start - respect vanish API
Expand All @@ -27,7 +27,7 @@ index caa73632aee15583c6b6ed12a668c8f49b794708..fa4c8a52a57775ef8f23e48e57b76ff7
}
// CraftBukkit end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 3be5e4df190bff0087c8450b16e4e37b07169040..960cc85150172eae9ba1eb1b6876ea8d21f2de34 100644
index c54df6e4aed9b7b46a41af4108a8e90d96c1fe1f..c856311f0f50d6e097b9acf27a630cae9fd855ba 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -181,7 +181,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
Expand Down
18 changes: 5 additions & 13 deletions patches/server/0014-Revert-Fix-MC-117075-TE-Unload-Lag-Spike.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <[email protected]>
Date: Sun, 26 Nov 2023 12:52:34 -0300
Date: Tue, 26 Dec 2023 16:45:54 -0300
Subject: [PATCH] Revert "Fix MC-117075: TE Unload Lag Spike"

This reverts commit 188c1c5b77133f7c3da9c67a97432d79d50d2b34.
This reverts commit f5e3e154a00754c18d557401cfb8d4aad5bc45e9.

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index f5e3c87581cbdc762806ad4412b68d3c84612b88..0740a7e90c8b7947448990cd9e76328d7d4a7e95 100644
index fdb86e3bcd48c9a27ca91e105bcd035de5781923..ed736827a7741a54e3a712cf5fcd19195aebaee5 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1281,8 +1281,6 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
Expand All @@ -18,15 +18,7 @@ index f5e3c87581cbdc762806ad4412b68d3c84612b88..0740a7e90c8b7947448990cd9e76328d
for (tileTickPosition = 0; tileTickPosition < this.blockEntityTickers.size(); tileTickPosition++) { // Paper - Disable tick limiters
this.tileTickPosition = (this.tileTickPosition < this.blockEntityTickers.size()) ? this.tileTickPosition : 0;
TickingBlockEntity tickingblockentity = (TickingBlockEntity) this.blockEntityTickers.get(this.tileTickPosition);
@@ -1290,6 +1288,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (tickingblockentity == null) {
this.getCraftServer().getLogger().severe("Spigot has detected a null entity and has removed it, preventing a crash");
tilesThisCycle--;
+ this.blockEntityTickers.remove(this.tileTickPosition--);
continue;
}
// Spigot end
@@ -1297,7 +1296,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1291,7 +1289,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (tickingblockentity.isRemoved()) {
// Spigot start
tilesThisCycle--;
Expand All @@ -35,7 +27,7 @@ index f5e3c87581cbdc762806ad4412b68d3c84612b88..0740a7e90c8b7947448990cd9e76328d
// Spigot end
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
tickingblockentity.tick();
@@ -1308,7 +1307,6 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1302,7 +1300,6 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// Paper end - execute chunk tasks during tick
}
}
Expand Down
121 changes: 109 additions & 12 deletions patches/server/0015-Fix-MC-117075-TE-Unload-Lag-Spike.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We replaced the `blockEntityTickers` list with a custom list based on fastutil's
This is WAY FASTER than using `removeAll` with a list of entries to be removed, because we don't need to calculate the identity of each block entity to be removed, and we can jump directly to where the search should begin, giving a performance boost for small removals (because we don't need to loop thru the entire list to find what element should be removed) and a performance boost for big removals (no need to calculate the identity of each block entity).

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 0740a7e90c8b7947448990cd9e76328d7d4a7e95..d9acec6352adf9e7d774cf3ea9486e57fc02ff83 100644
index ed736827a7741a54e3a712cf5fcd19195aebaee5..7681bce91247c13c8211ed6fd2a2998b815604f0 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -120,7 +120,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
Expand All @@ -20,16 +20,7 @@ index 0740a7e90c8b7947448990cd9e76328d7d4a7e95..d9acec6352adf9e7d774cf3ea9486e57
protected final NeighborUpdater neighborUpdater;
private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
private boolean tickingBlockEntities;
@@ -1288,7 +1288,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (tickingblockentity == null) {
this.getCraftServer().getLogger().severe("Spigot has detected a null entity and has removed it, preventing a crash");
tilesThisCycle--;
- this.blockEntityTickers.remove(this.tileTickPosition--);
+ this.blockEntityTickers.markAsRemoved(this.tileTickPosition); // this.blockEntityTickers.remove(this.tileTickPosition--); // SparklyPaper - optimize block entity removals
continue;
}
// Spigot end
@@ -1296,7 +1296,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1289,7 +1289,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (tickingblockentity.isRemoved()) {
// Spigot start
tilesThisCycle--;
Expand All @@ -38,7 +29,7 @@ index 0740a7e90c8b7947448990cd9e76328d7d4a7e95..d9acec6352adf9e7d774cf3ea9486e57
// Spigot end
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
tickingblockentity.tick();
@@ -1307,7 +1307,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1300,7 +1300,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// Paper end - execute chunk tasks during tick
}
}
Expand Down Expand Up @@ -153,3 +144,109 @@ index 0000000000000000000000000000000000000000..7affec7e343c39a83390ae13ce23f3bf
+ size = j;
+ }
+}
diff --git a/src/main/kotlin/net/sparklypower/sparklypaper/BlockEntityTickersList.java b/src/main/kotlin/net/sparklypower/sparklypaper/BlockEntityTickersList.java
new file mode 100644
index 0000000000000000000000000000000000000000..7affec7e343c39a83390ae13ce23f3bfa0db1eb6
--- /dev/null
+++ b/src/main/kotlin/net/sparklypower/sparklypaper/BlockEntityTickersList.java
@@ -0,0 +1,100 @@
+package net.sparklypower.sparklypaper;
+
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import net.minecraft.world.level.block.entity.TickingBlockEntity;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A list for ServerLevel's blockEntityTickers
+ *
+ * This list is behaves identically to ObjectArrayList, but it has an additional method, `removeAllByIndex`, that allows a list of integers to be passed indicating what
+ * indexes should be deleted from the list
+ *
+ * This is faster than using removeAll, since we don't need to compare the identity of each block entity, and faster than looping thru each index manually and deleting with remove,
+ * since we don't need to resize the array every single remove.
+ */
+public final class BlockEntityTickersList extends ObjectArrayList<TickingBlockEntity> {
+ private final IntOpenHashSet toRemove = new IntOpenHashSet();
+ private int startSearchFromIndex = -1;
+
+ /** Creates a new array list with {@link #DEFAULT_INITIAL_CAPACITY} capacity. */
+ public BlockEntityTickersList() {
+ super();
+ }
+
+ /**
+ * Creates a new array list and fills it with a given collection.
+ *
+ * @param c a collection that will be used to fill the array list.
+ */
+ public BlockEntityTickersList(final Collection<? extends TickingBlockEntity> c) {
+ super(c);
+ }
+
+ /**
+ * Marks an entry as removed
+ *
+ * @param index the index of the item on the list to be marked as removed
+ */
+ public void markAsRemoved(final int index) {
+ // The block entities list always loop starting from 0, so we only need to check if the startSearchFromIndex is -1 and that's it
+ if (this.startSearchFromIndex == -1)
+ this.startSearchFromIndex = index;
+ this.toRemove.add(index);
+ }
+
+ /**
+ * Removes elements that have been marked as removed.
+ */
+ public void removeMarkedEntries() {
+ if (this.startSearchFromIndex == -1) // No entries in the list, skip
+ return;
+
+ removeAllByIndex(startSearchFromIndex, toRemove);
+ toRemove.clear();
+ this.startSearchFromIndex = -1; // Reset the start search index
+ }
+
+ /**
+ * Removes elements by their index.
+ */
+ private void removeAllByIndex(final int startSearchFromIndex, final IntOpenHashSet c) { // can't use Set<Integer> because we want to avoid autoboxing when using contains
+ final int requiredMatches = c.size();
+ if (requiredMatches == 0)
+ return; // exit early, we don't need to do anything
+
+ final Object[] a = this.a;
+ int j = startSearchFromIndex;
+ int matches = 0;
+ for (int i = startSearchFromIndex; i < size; i++) { // If the user knows the first index to be removed, we can skip a lot of unnecessary comparsions
+ if (!c.contains(i)) {
+ // TODO: It can be possible to optimize this loop by tracking the start/finish and then using arraycopy to "skip" the elements,
+ // this would optimize cases where the index to be removed are far apart, HOWEVER it does have a big performance impact if you are doing
+ // "arraycopy" for each element
+ a[j++] = a[i];
+ } else {
+ matches++;
+ }
+
+ if (matches == requiredMatches) { // Exit the loop if we already removed everything, we don't need to check anything else
+ // We need to update the final size here, because we know that we already found everything!
+ // Because we know that the size must be currentSize - requiredMatches (because we have matched everything), let's update the value
+ // However, we need to copy the rest of the stuff over
+ if (i != (size - 1)) { // If it isn't the last index...
+ // i + 1 because we want to copy the *next* element over
+ // and the size - i - 1 is because we want to get the current size, minus the current index (which is i), and then - 1 because we want to copy -1 ahead (remember, we are adding +1 to copy the *next* element)
+ System.arraycopy(a, i + 1, a, j, size - i - 1);
+ }
+ j = size - requiredMatches;
+ break;
+ }
+ }
+ Arrays.fill(a, j, size, null);
+ size = j;
+ }
+}
4 changes: 2 additions & 2 deletions patches/server/0016-Optimize-tickBlockEntities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ But here's the thing: We don't care if we have a small performance penalty if th
And finally, we also cache the chunk's coordinate key when creating the block entity, which is actually "free" because we just reuse the already cached chunk coordinate key from the chunk!

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index d9acec6352adf9e7d774cf3ea9486e57fc02ff83..4c0aa4b4c79562d43df9fc07a56731056f6a2348 100644
index 7681bce91247c13c8211ed6fd2a2998b815604f0..608259c6092f5353e818b5fbeb0e1a5249ed136b 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1281,6 +1281,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
Expand All @@ -26,7 +26,7 @@ index d9acec6352adf9e7d774cf3ea9486e57fc02ff83..4c0aa4b4c79562d43df9fc07a5673105
for (tileTickPosition = 0; tileTickPosition < this.blockEntityTickers.size(); tileTickPosition++) { // Paper - Disable tick limiters
this.tileTickPosition = (this.tileTickPosition < this.blockEntityTickers.size()) ? this.tileTickPosition : 0;
TickingBlockEntity tickingblockentity = (TickingBlockEntity) this.blockEntityTickers.get(this.tileTickPosition);
@@ -1298,13 +1302,25 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1291,13 +1295,25 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
tilesThisCycle--;
this.blockEntityTickers.markAsRemoved(this.tileTickPosition); // this.blockEntityTickers.remove(this.tileTickPosition--); // SparklyPaper - optimize block entity removals
// Spigot end
Expand Down
Loading

0 comments on commit 22b3025

Please sign in to comment.