Paper/Spigot-Server-Patches/0478-Optimize-ChunkProviderServer-s-chunk-level-checking-.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

63 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 16 Apr 2020 16:13:59 -0700
Subject: [PATCH] Optimize ChunkProviderServer's chunk level checking helper
methods
These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 377d554553ce81f66207541d963f826867e66592..9afbec260a1d586152073b2adda32959453ab8c9 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -606,27 +606,37 @@ public class ChunkProviderServer extends IChunkProvider {
public final boolean isInEntityTickingChunk(Entity entity) { return this.a(entity); } // Paper - OBFHELPER
@Override public boolean a(Entity entity) {
- long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4);
-
- return this.a(i, PlayerChunk::b);
+ // Paper start - optimize is ticking ready type functions
+ // entity ticking
+ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(entity));
+ return playerChunk != null && playerChunk.isEntityTickingReady();
+ // Paper end - optimize is ticking ready type functions
}
public final boolean isEntityTickingChunk(ChunkCoordIntPair chunkcoordintpair) { return this.a(chunkcoordintpair); } // Paper - OBFHELPER
@Override public boolean a(ChunkCoordIntPair chunkcoordintpair) {
- return this.a(chunkcoordintpair.pair(), PlayerChunk::b);
+ // Paper start - optimize is ticking ready type functions
+ // is entity ticking ready
+ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(chunkcoordintpair));
+ return playerChunk != null && playerChunk.isEntityTickingReady();
+ // Paper end - optimize is ticking ready type functions
}
@Override
public boolean a(BlockPosition blockposition) {
- long i = ChunkCoordIntPair.pair(blockposition.getX() >> 4, blockposition.getZ() >> 4);
-
- return this.a(i, PlayerChunk::a);
+ // Paper start - optimize is ticking ready type functions
+ // is ticking ready
+ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(blockposition));
+ return playerChunk != null && playerChunk.isTickingReady();
+ // Paper end - optimize is ticking ready type functions
}
public boolean b(Entity entity) {
- long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4);
-
- return this.a(i, PlayerChunk::c);
+ // Paper start - optimize is ticking ready type functions
+ // is full chunk ready
+ PlayerChunk playerChunk = this.getChunk(MCUtil.getCoordinateKey(entity));
+ return playerChunk != null && playerChunk.isFullChunkReady();
+ // Paper end - optimize is ticking ready type functions
}
private boolean a(long i, Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>> function) {