3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/patches/server/0409-Reduce-MutableInt-allocations-from-light-engine.patch

51 Zeilen
3.3 KiB
Diff

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: Mon, 27 Apr 2020 02:48:06 -0700
Subject: [PATCH] Reduce MutableInt allocations from light engine
We can abuse the fact light is single threaded and share an instance
per light engine instance
diff --git a/src/main/java/net/minecraft/world/level/lighting/BlockLightEngine.java b/src/main/java/net/minecraft/world/level/lighting/BlockLightEngine.java
2021-06-14 07:32:56 +02:00
index 729c4b1763a24bac3c0764bea505555a32e54f57..37d7165dfd17da03428f8dbbbf95aa8005be289c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/lighting/BlockLightEngine.java
+++ b/src/main/java/net/minecraft/world/level/lighting/BlockLightEngine.java
2021-06-14 07:32:56 +02:00
@@ -15,6 +15,7 @@ import org.apache.commons.lang3.mutable.MutableInt;
public final class BlockLightEngine extends LayerLightEngine<BlockLightSectionStorage.BlockDataLayerStorageMap, BlockLightSectionStorage> {
2021-06-11 14:02:28 +02:00
private static final Direction[] DIRECTIONS = Direction.values();
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
2021-06-14 07:32:56 +02:00
+ private final MutableInt mutableInt = new MutableInt(); // Paper
2021-06-11 14:02:28 +02:00
public BlockLightEngine(LightChunkGetter chunkProvider) {
super(chunkProvider, LightLayer.BLOCK, new BlockLightSectionStorage(chunkProvider));
2021-06-14 07:32:56 +02:00
@@ -44,7 +45,7 @@ public final class BlockLightEngine extends LayerLightEngine<BlockLightSectionSt
if (direction == null) {
2021-06-11 14:02:28 +02:00
return 15;
} else {
2021-06-14 07:32:56 +02:00
- MutableInt mutableInt = new MutableInt();
2021-06-11 14:02:28 +02:00
+ //MutableInt mutableint = new MutableInt(); // Paper - share mutableint, single threaded
2021-06-14 07:32:56 +02:00
BlockState blockState = this.getStateAndOpacity(targetId, mutableInt);
if (mutableInt.getValue() >= 15) {
return 15;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/lighting/SkyLightEngine.java b/src/main/java/net/minecraft/world/level/lighting/SkyLightEngine.java
2022-07-27 22:17:18 +02:00
index 56b8f6ac53e7598da4dea2180825242222f86731..ca710a20e8b97341616463f4058b61cf4999af28 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/lighting/SkyLightEngine.java
+++ b/src/main/java/net/minecraft/world/level/lighting/SkyLightEngine.java
2022-07-27 22:17:18 +02:00
@@ -15,6 +15,7 @@ import org.apache.commons.lang3.mutable.MutableInt;
2021-06-14 07:32:56 +02:00
public final class SkyLightEngine extends LayerLightEngine<SkyLightSectionStorage.SkyDataLayerStorageMap, SkyLightSectionStorage> {
2021-06-11 14:02:28 +02:00
private static final Direction[] DIRECTIONS = Direction.values();
private static final Direction[] HORIZONTALS = new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST};
2021-06-14 07:32:56 +02:00
+ private final MutableInt mutableInt = new MutableInt(); // Paper
2021-06-11 14:02:28 +02:00
public SkyLightEngine(LightChunkGetter chunkProvider) {
super(chunkProvider, LightLayer.SKY, new SkyLightSectionStorage(chunkProvider));
2022-07-27 22:17:18 +02:00
@@ -26,7 +27,7 @@ public final class SkyLightEngine extends LayerLightEngine<SkyLightSectionStorag
2021-06-11 14:02:28 +02:00
if (level >= 15) {
return level;
} else {
2021-06-14 07:32:56 +02:00
- MutableInt mutableInt = new MutableInt();
2021-06-11 14:02:28 +02:00
+ //MutableInt mutableint = new MutableInt(); // Paper - share mutableint, single threaded
2021-06-14 07:32:56 +02:00
BlockState blockState = this.getStateAndOpacity(targetId, mutableInt);
if (mutableInt.getValue() >= 15) {
return 15;