Paper/patches/server/0466-Optimise-getType-calls.patch

95 lines
5.1 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
2021-06-11 14:02:28 +02:00
Date: Wed, 3 Jun 2020 11:37:13 -0700
Subject: [PATCH] Optimise getType calls
Remove the map lookup for converting from Block->Bukkit Material
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockState.java b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
2023-09-22 19:59:56 +02:00
index da878e180c6b94f98dc82c6e8395f63ecc9b2c1e..a9b0f5950b6f97ea4c2a1075946b92008b62c9d9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/state/BlockState.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
2021-06-14 18:58:00 +02:00
@@ -10,6 +10,17 @@ import net.minecraft.world.level.block.state.properties.Property;
public class BlockState extends BlockBehaviour.BlockStateBase {
2022-12-07 21:16:54 +01:00
public static final Codec<BlockState> CODEC = codec(BuiltInRegistries.BLOCK.byNameCodec(), Block::defaultBlockState).stable();
2021-06-11 14:02:28 +02:00
+ // Paper start - optimise getType calls
+ org.bukkit.Material cachedMaterial;
+
+ public final org.bukkit.Material getBukkitMaterial() {
+ if (this.cachedMaterial == null) {
+ this.cachedMaterial = org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(this.getBlock());
+ }
+
+ return this.cachedMaterial;
+ }
+ // Paper end - optimise getType calls
2021-06-14 18:58:00 +02:00
public BlockState(Block block, ImmutableMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
super(block, propertyMap, codec);
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
2023-10-27 01:34:58 +02:00
index 089f2a4780a0e3515c032d08a1bb2ea375ebdce1..30f6d74e867869b0070de83fe988672a74580043 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
@@ -98,7 +98,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
2021-06-11 14:02:28 +02:00
public Material getBlockType(int x, int y, int z) {
2021-06-14 18:58:00 +02:00
this.validateChunkCoordinates(x, y, z);
2021-06-11 14:02:28 +02:00
2021-06-14 18:58:00 +02:00
- return CraftMagicNumbers.getMaterial(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBlock());
+ return this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise getType calls
2021-06-11 14:02:28 +02:00
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2023-12-06 04:00:14 +01:00
index a7783474afef0a2bab7e99e475c6d130bb88b01c..aa644231425b9622437538b5c092d4064a40cced 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2023-12-06 04:00:14 +01:00
@@ -220,7 +220,7 @@ public class CraftBlock implements Block {
2021-06-11 14:02:28 +02:00
@Override
public Material getType() {
2023-10-27 01:34:58 +02:00
- return CraftMagicNumbers.getMaterial(this.world.getBlockState(this.position).getBlock());
2021-06-14 18:58:00 +02:00
+ return this.world.getBlockState(this.position).getBukkitMaterial(); // Paper - optimise getType calls
2021-06-11 14:02:28 +02:00
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
2023-10-27 01:34:58 +02:00
index a193583f596c0a587cd0c2d6eac994226ee4fde0..aca63719790429d3d7c7c59a1931a98221c70fc0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -170,7 +170,7 @@ public class CraftBlockState implements BlockState {
2021-06-11 14:02:28 +02:00
@Override
public Material getType() {
2021-06-14 18:58:00 +02:00
- return CraftMagicNumbers.getMaterial(this.data.getBlock());
+ return this.data.getBukkitMaterial(); // Paper - optimise getType calls
2021-06-11 14:02:28 +02:00
}
public void setFlag(int flag) {
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
index c1506afacb6a73ef4a4692c0ae0722b240f01606..89997c2a11b247d2a23dc7c176bce3231639e777 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -60,7 +60,7 @@ public class CraftBlockData implements BlockData {
2021-06-11 14:02:28 +02:00
@Override
public Material getMaterial() {
2021-06-14 18:58:00 +02:00
- return CraftMagicNumbers.getMaterial(this.state.getBlock());
+ return this.state.getBukkitMaterial(); // Paper - optimise getType calls
2021-06-11 14:02:28 +02:00
}
public net.minecraft.world.level.block.state.BlockState getState() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
index 35cf747196b43a0f1d9237fdc12424288962f8bd..54c7877f1da51ff8be467fac5e0a37b1fd573d37 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
@@ -95,7 +95,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
2021-06-11 14:02:28 +02:00
@Override
public Material getType(int x, int y, int z) {
2021-06-14 18:58:00 +02:00
- return CraftMagicNumbers.getMaterial(this.getTypeId(x, y, z).getBlock());
+ return this.getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls
2021-06-11 14:02:28 +02:00
}
@Override