papermc/Spigot-Server-Patches/0523-Reduce-MutableInt-allocations-from-light-engine.patch
Aikar 614a664bd3
Implement Chunk Priority / Urgency System for Chunks
Mark chunks that are blocking main thread for world generation as urgent

Implements a general priority system so that chunks that are sorted in
the generator queues can prioritize certain chunks over another.

Urgent chunks will jump to the front of the line, ensuring that a
sync chunk load on an ungenerated chunk does not lag the server for
a long period of time if the servers generator queues are filled with
lots of chunks already.

This massively reduces the lag spikes from sync chunk gens.

Then we further prioritize loading order so nearby chunks have higher
priority than distant chunks, reducing the pressure a high no tick
view distance holds on you.

Chunks in front of the player have higher priority, to help with
fast traveling players keep up with their movement.

This commit also improves single core cpu scenarios in that we will
now automatically disable Async Chunks as well as Minecrafts thread
pool.

It is never recommended to use async chunks on a single CPU as context
switching will be slower than just running it all on main.

This also bumps the number of server worker threads by default too.
Mojang does not utilize the workers in an effecient manner, resulting
in them using barely any sustained CPU.

So give it more workers so more chunks can be processed concurrently

This change also improves urgent chunk loading, so players flying into
unloaded chunks will hurt a little bit less (but still hurt)

Ping #3395 #3363 (Not marking as closed, we need to make prevent moving work)
2020-05-19 04:09:37 -04:00

60 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
Date: Mon, 27 Apr 2020 02:48:06 -0700
Subject: [PATCH] Reduce MutableInt allocations from light engine
diff --git a/src/main/java/net/minecraft/server/LightEngineBlock.java b/src/main/java/net/minecraft/server/LightEngineBlock.java
index 93a972605c26aa757b9c915876f847da04fcb496..c9e91eb4ef538485620aedaee4843b779fede809 100644
--- a/src/main/java/net/minecraft/server/LightEngineBlock.java
+++ b/src/main/java/net/minecraft/server/LightEngineBlock.java
@@ -37,7 +37,10 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB
if (enumdirection == null) {
return 15;
} else {
- MutableInt mutableint = new MutableInt();
+ // Paper start - reduce mutableint allocations
+ MutableInt mutableint = com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.acquire();
+ try {
+ // Paper end - reduce mutableint allocations
IBlockData iblockdata = this.a(j, mutableint);
if (mutableint.getValue() >= 15) {
@@ -49,6 +52,10 @@ public final class LightEngineBlock extends LightEngineLayer<LightEngineStorageB
return VoxelShapes.b(voxelshape, voxelshape1) ? 15 : k + Math.max(1, mutableint.getValue());
}
+ } finally { // Paper start - reduce mutableint allocations
+ com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.release(mutableint);
+ }
+ // Paper end - reduce mutableint allocations
}
}
}
diff --git a/src/main/java/net/minecraft/server/LightEngineSky.java b/src/main/java/net/minecraft/server/LightEngineSky.java
index 2301a982e17ab9568e3da9ca84c4a024c7c1b214..57c2880ea23dc7ff55826858240bd13b7d3c24f2 100644
--- a/src/main/java/net/minecraft/server/LightEngineSky.java
+++ b/src/main/java/net/minecraft/server/LightEngineSky.java
@@ -27,7 +27,10 @@ public final class LightEngineSky extends LightEngineLayer<LightEngineStorageSky
if (k >= 15) {
return k;
} else {
- MutableInt mutableint = new MutableInt();
+ // Paper start - reduce mutableint allocations
+ MutableInt mutableint = com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.acquire();
+ try {
+ // Paper end - reduce mutableint allocations
IBlockData iblockdata = this.a(j, mutableint);
if (mutableint.getValue() >= 15) {
@@ -85,6 +88,10 @@ public final class LightEngineSky extends LightEngineLayer<LightEngineStorageSky
return flag1 && k == 0 && mutableint.getValue() == 0 ? 0 : k + Math.max(1, mutableint.getValue());
}
+ } finally { // Paper start - reduce mutableint allocations
+ com.destroystokyo.paper.util.pooled.PooledObjects.POOLED_MUTABLE_INTEGERS.release(mutableint);
+ }
+ // Paper end - reduce mutableint allocations
}
}
}