Skip to content

Commit

Permalink
More performance
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 20, 2023
1 parent 0fa0521 commit 8623381
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 2 deletions.
29 changes: 27 additions & 2 deletions patches/server/0004-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ index 35d2da9d91dcdd89de7c0f4af028fd182376ea8d..d73482fb1e71fe2951e96ae0593de268
.withRequiredArg()
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..b72d7a188183c6fb3f9ed8978336bc1a188854d4
index 0000000000000000000000000000000000000000..6a0d108652cca434a75144595fb2cd77c9ccae9e
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,901 @@
@@ -0,0 +1,926 @@
+package top.leavesmc.leaves;
+
+import com.destroystokyo.paper.util.SneakyThrow;
Expand Down Expand Up @@ -858,6 +858,31 @@ index 0000000000000000000000000000000000000000..b72d7a188183c6fb3f9ed8978336bc1a
+ useOptimizedCollection = getBoolean("settings.performance.use-optimized-collection", useOptimizedCollection);
+ }
+
+ public static boolean optimizedCubePointRange = true;
+ private static void optimizedCubePointRange() {
+ optimizedCubePointRange = getBoolean("settings.performance.optimized-CubePointRange", optimizedCubePointRange);
+ }
+
+ public static boolean checkFrozenTicksBeforeLandingBlock = true;
+ private static void checkFrozenTicksBeforeLandingBlock() {
+ checkFrozenTicksBeforeLandingBlock = getBoolean("settings.performance.check-frozen-ticks-before-landing-block", checkFrozenTicksBeforeLandingBlock);
+ }
+
+ public static boolean cacheOminousBannerItem = true;
+ private static void cacheOminousBannerItem() {
+ cacheOminousBannerItem = getBoolean("settings.performance.cache-ominous-banner-item", cacheOminousBannerItem);
+ }
+
+ public static boolean skipEntityMoveIfMovementIsZero = true;
+ private static void skipEntityMoveIfMovementIsZero() {
+ skipEntityMoveIfMovementIsZero = getBoolean("settings.performance.skip-entity-move-if-movement-is-zero", skipEntityMoveIfMovementIsZero);
+ }
+
+ public static boolean skipCloningAdvancementCriteria = false;
+ private static void skipCloningAdvancementCriteria() {
+ skipCloningAdvancementCriteria = getBoolean("settings.performance.skip-cloning-advancement-criteria", skipCloningAdvancementCriteria);
+ }
+
+ public static final class WorldConfig {
+
+ public final String worldName;
Expand Down
13 changes: 13 additions & 0 deletions patches/server/0102-Use-optimized-collection.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ Subject: [PATCH] Use optimized collection

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 445582a852826f177f220e3bcd96db3030134f64..092c7a1430c1e380cdaec308624afce0733a4556 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -295,7 +295,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// Paper - rewrite chunk system
this.tickingGenerated = new AtomicInteger();
this.playerMap = new PlayerMap();
- this.entityMap = new Int2ObjectOpenHashMap();
+ this.entityMap = top.leavesmc.leaves.LeavesConfig.useOptimizedCollection ? new it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap() : new Int2ObjectOpenHashMap(); // Leaves - se linked map for entity trackers - provides faster iteration
this.chunkTypeCache = new Long2ByteOpenHashMap();
this.chunkSaveCooldowns = new Long2LongOpenHashMap();
this.unloadQueue = Queues.newConcurrentLinkedQueue();
diff --git a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java b/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
index 50a9f33aa31e9273c7c52d4bb2b02f0f884f7ba5..53021c7d173b3c067322e356fead0949aac3fc60 100644
--- a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
Expand Down
45 changes: 45 additions & 0 deletions patches/server/0104-Optimized-CubePointRange.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Thu, 20 Jul 2023 20:22:47 +0800
Subject: [PATCH] Optimized CubePointRange

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java b/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
index a544db042c8d2ecec8d323770552c4f10ca758a6..81d18ce2ee4342b466c6623bcad7840c929eb79d 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
@@ -3,21 +3,31 @@ package net.minecraft.world.phys.shapes;
import it.unimi.dsi.fastutil.doubles.AbstractDoubleList;

public class CubePointRange extends AbstractDoubleList {
+ private final int size; // Leaves - replace parts by size in CubePointRange
private final int parts;
+ private final double scale; // Leaves - replace division by multiplication in CubePointRange

CubePointRange(int sectionCount) {
if (sectionCount <= 0) {
throw new IllegalArgumentException("Need at least 1 part");
} else {
this.parts = sectionCount;
+ this.size = sectionCount + 1;
}
+ this.scale = 1.0D / sectionCount; // Leaves - replace division by multiplication in CubePointRange
}

public double getDouble(int i) {
- return (double)i / (double)this.parts;
+ // Leaves start - replace division by multiplication in CubePointRange
+ if (!top.leavesmc.leaves.LeavesConfig.optimizedCubePointRange) {
+ return (double)i / (double)this.parts;
+ } else {
+ return i * this.scale;
+ }
+ // Leaves start - replace division by multiplication in CubePointRange
}

public int size() {
- return this.parts + 1;
+ return !top.leavesmc.leaves.LeavesConfig.optimizedCubePointRange ? this.parts + 1 : size; // Leaves - replace parts by size in CubePointRange
}
}
25 changes: 25 additions & 0 deletions patches/server/0105-Check-frozen-ticks-before-landing-block.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Thu, 20 Jul 2023 20:33:52 +0800
Subject: [PATCH] Check frozen ticks before landing block

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 94179dafe22403b4aaa6adcff879b459a073ad09..a930062bd4a43df7f74d92ab8a178f13528204d8 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -583,11 +583,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

protected void tryAddFrost() {
- if (!this.getBlockStateOnLegacy().isAir()) {
+ if (top.leavesmc.leaves.LeavesConfig.checkFrozenTicksBeforeLandingBlock || !this.getBlockStateOnLegacy().isAir()) { // Leaves - check frozen ticks before landing block
int i = this.getTicksFrozen();

if (i > 0) {
- AttributeInstance attributemodifiable = this.getAttribute(Attributes.MOVEMENT_SPEED);
+ AttributeInstance attributemodifiable = !top.leavesmc.leaves.LeavesConfig.checkFrozenTicksBeforeLandingBlock || !this.getBlockStateOnLegacy().isAir() ? this.getAttribute(Attributes.MOVEMENT_SPEED) : null; // Leaves - check frozen ticks before landing block

if (attributemodifiable == null) {
return;
79 changes: 79 additions & 0 deletions patches/server/0106-Cache-ominous-banner-item.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Thu, 20 Jul 2023 21:02:10 +0800
Subject: [PATCH] Cache ominous banner item

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/advancements/critereon/EntityEquipmentPredicate.java b/src/main/java/net/minecraft/advancements/critereon/EntityEquipmentPredicate.java
index b8ef0f9c815799d54edcdb26dc0b4c1c281fc03e..85ccff2938dc138e5d309448cd631fe534effd42 100644
--- a/src/main/java/net/minecraft/advancements/critereon/EntityEquipmentPredicate.java
+++ b/src/main/java/net/minecraft/advancements/critereon/EntityEquipmentPredicate.java
@@ -13,7 +13,7 @@ import net.minecraft.world.item.Items;

public class EntityEquipmentPredicate {
public static final EntityEquipmentPredicate ANY = new EntityEquipmentPredicate(ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
- public static final EntityEquipmentPredicate CAPTAIN = new EntityEquipmentPredicate(ItemPredicate.Builder.item().of(Items.WHITE_BANNER).hasNbt(Raid.getLeaderBannerInstance().getTag()).build(), ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
+ public static final EntityEquipmentPredicate CAPTAIN = new EntityEquipmentPredicate(ItemPredicate.Builder.item().of(Items.WHITE_BANNER).hasNbt(top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? Raid.LEADER_BANNER.getTag() : Raid.getLeaderBannerInstance().getTag()).build(), ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY); // Leaves - cache ominous banner item
private final ItemPredicate head;
private final ItemPredicate chest;
private final ItemPredicate legs;
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
index f7399737548483905f3b5c08a03876b0da54b714..dc3aed4130b78e91382a6e973ae83ea4a0524f41 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
@@ -689,7 +689,14 @@ public class Raid {
this.level.getRaids().setDirty();
}

+ // Leaves start - cache ominous banner item
+ public static final ItemStack LEADER_BANNER = createLeaderBanner();
public static ItemStack getLeaderBannerInstance() {
+ return top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? LEADER_BANNER.copy() : createLeaderBanner();
+ }
+ // Leaves end - cache ominous banner item
+
+ public static ItemStack createLeaderBanner() { // Leaves - cache ominous banner item
ItemStack itemstack = new ItemStack(Items.WHITE_BANNER);
CompoundTag nbttagcompound = new CompoundTag();
ListTag nbttaglist = (new BannerPattern.Builder()).addPattern(BannerPatterns.RHOMBUS_MIDDLE, DyeColor.CYAN).addPattern(BannerPatterns.STRIPE_BOTTOM, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_CENTER, DyeColor.GRAY).addPattern(BannerPatterns.BORDER, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.STRIPE_MIDDLE, DyeColor.BLACK).addPattern(BannerPatterns.HALF_HORIZONTAL, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.CIRCLE_MIDDLE, DyeColor.LIGHT_GRAY).addPattern(BannerPatterns.BORDER, DyeColor.BLACK).toListTag();
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raider.java b/src/main/java/net/minecraft/world/entity/raid/Raider.java
index 1b8e141e50dd2a156eda2455988ea45a390692ae..f3029db1e2a16619def35f1bf7807dd1052d3036 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raider.java
+++ b/src/main/java/net/minecraft/world/entity/raid/Raider.java
@@ -47,7 +47,7 @@ public abstract class Raider extends PatrollingMonster {

protected static final EntityDataAccessor<Boolean> IS_CELEBRATING = SynchedEntityData.defineId(Raider.class, EntityDataSerializers.BOOLEAN);
static final Predicate<ItemEntity> ALLOWED_ITEMS = (entityitem) -> {
- return !entityitem.hasPickUpDelay() && entityitem.isAlive() && ItemStack.matches(entityitem.getItem(), Raid.getLeaderBannerInstance());
+ return !entityitem.hasPickUpDelay() && entityitem.isAlive() && ItemStack.matches(entityitem.getItem(), top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? Raid.LEADER_BANNER : Raid.getLeaderBannerInstance()); // Leaves - cache ominous banner item
};
@Nullable
protected Raid raid;
@@ -149,7 +149,7 @@ public abstract class Raider extends PatrollingMonster {
}
}

- if (!itemstack.isEmpty() && ItemStack.matches(itemstack, Raid.getLeaderBannerInstance()) && entityhuman != null) {
+ if (!itemstack.isEmpty() && ItemStack.matches(itemstack, top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? Raid.LEADER_BANNER : Raid.getLeaderBannerInstance()) && entityhuman != null) { // Leaves - cache ominous banner item
MobEffectInstance mobeffect = entityhuman.getEffect(MobEffects.BAD_OMEN);
byte b0 = 1;
int i;
@@ -244,7 +244,7 @@ public abstract class Raider extends PatrollingMonster {
ItemStack itemstack = item.getItem();
boolean flag = this.hasActiveRaid() && this.getCurrentRaid().getLeader(this.getWave()) != null;

- if (this.hasActiveRaid() && !flag && ItemStack.matches(itemstack, Raid.getLeaderBannerInstance())) {
+ if (this.hasActiveRaid() && !flag && ItemStack.matches(itemstack, top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? Raid.LEADER_BANNER : Raid.getLeaderBannerInstance())) { // Leaves - cache ominous banner item
// Paper start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, item, 0, false).isCancelled()) {
return;
@@ -322,7 +322,7 @@ public abstract class Raider extends PatrollingMonster {
if (!this.mob.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || !this.mob.canPickUpLoot()) return false; // Paper - respect game and entity rules for picking up items
Raid raid = this.mob.getCurrentRaid();

- if (this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && this.mob.canBeLeader() && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), Raid.getLeaderBannerInstance())) {
+ if (this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && this.mob.canBeLeader() && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), top.leavesmc.leaves.LeavesConfig.cacheOminousBannerItem ? Raid.LEADER_BANNER : Raid.getLeaderBannerInstance())) { // Leaves - cache ominous banner item
Raider entityraider = raid.getLeader(this.mob.getWave());

if (entityraider == null || !entityraider.isAlive()) {
41 changes: 41 additions & 0 deletions patches/server/0107-Skip-entity-move-if-movement-is-zero.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Thu, 20 Jul 2023 21:13:28 +0800
Subject: [PATCH] Skip entity move if movement is zero

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 40f3d47eb085663c979719bd648ac593abf0e786..501208a0407829c72204625964fac40a11384563 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -314,6 +314,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
public float yRotO;
public float xRotO;
private AABB bb;
+ private boolean boundingBoxChanged = false; // Leaves - skip entity move if movement is zero
public boolean onGround;
public boolean horizontalCollision;
public boolean verticalCollision;
@@ -1067,6 +1068,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
// Paper end - detailed watchdog information

public void move(MoverType movementType, Vec3 movement) {
+ // Leaves start - skip entity move if movement is zero
+ if (top.leavesmc.leaves.LeavesConfig.skipEntityMoveIfMovementIsZero) {
+ if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) {
+ return;
+ }
+ }
+ // Leaves end - skip entity move if movement is zero
// Paper start - detailed watchdog information
io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
synchronized (this.posLock) {
@@ -3988,6 +3996,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
}

public final void setBoundingBox(AABB boundingBox) {
+ if (!this.bb.equals(boundingBox)) this.boundingBoxChanged = true; // Leaves - skip entity move if movement is zero
// CraftBukkit start - block invalid bounding boxes
double minX = boundingBox.minX,
minY = boundingBox.minY,
20 changes: 20 additions & 0 deletions patches/server/0108-Skip-cloning-advancement-criteria.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Thu, 20 Jul 2023 21:30:17 +0800
Subject: [PATCH] Skip cloning advancement criteria

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/advancements/Advancement.java b/src/main/java/net/minecraft/advancements/Advancement.java
index 81359be381fc9bcb56a9cc83e70a6afa6e838c6a..23f930775d8d684da915ca72ca1c4b27572fb056 100644
--- a/src/main/java/net/minecraft/advancements/Advancement.java
+++ b/src/main/java/net/minecraft/advancements/Advancement.java
@@ -46,7 +46,7 @@ public class Advancement {
public Advancement(ResourceLocation id, @Nullable Advancement parent, @Nullable DisplayInfo display, AdvancementRewards rewards, Map<String, Criterion> criteria, String[][] requirements, boolean sendsTelemetryEvent) {
this.id = id;
this.display = display;
- this.criteria = ImmutableMap.copyOf(criteria);
+ this.criteria = !top.leavesmc.leaves.LeavesConfig.skipCloningAdvancementCriteria ? ImmutableMap.copyOf(criteria) : criteria; // Leaves - skip cloning advancement criteria
this.parent = parent;
this.rewards = rewards;
this.requirements = requirements;

0 comments on commit 8623381

Please sign in to comment.