From 976c2955146c22961cbe60c245bcae648e90321a Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 8 Oct 2020 01:07:10 -0400 Subject: [PATCH] Improve Priority handling of neighbor chunks Restores vanilla like behavior where neighbor chunks have less priority than the source chunk. This resolves the issue where teleporting sometimes has the chunk your arriving in slow to send. Also improves light tasks to always process tasks when tasks from the current priority level are collected instead of bundling them. --- ...nt-Chunk-Priority-Urgency-System-for-Chunks.patch | 2 +- Spigot-Server-Patches/Optimize-Light-Engine.patch | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch index fea2e2005..19a19abb7 100644 --- a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch +++ b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch @@ -687,7 +687,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + private int getNeighborsPriority() { -+ return neighborPriorities.isEmpty() ? getMyPriority() : getDemandedPriority(); ++ return (neighborPriorities.isEmpty() ? getMyPriority() : getDemandedPriority()) + 1; + } + + public void onNeighborRequest(PlayerChunk neighbor, ChunkStatus status) { diff --git a/Spigot-Server-Patches/Optimize-Light-Engine.patch b/Spigot-Server-Patches/Optimize-Light-Engine.patch index a550c9796..2c0266983 100644 --- a/Spigot-Server-Patches/Optimize-Light-Engine.patch +++ b/Spigot-Server-Patches/Optimize-Light-Engine.patch @@ -1098,7 +1098,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + this.priorityChanges.add(() -> { + ChunkLightQueue remove = this.buckets[currentPriority].remove(pair); + if (remove != null) { -+ ChunkLightQueue existing = this.buckets[priority].put(pair, remove); ++ ChunkLightQueue existing = this.buckets[Math.max(1, priority)].put(pair, remove); + if (existing != null) { + remove.pre.addAll(existing.pre); + remove.post.addAll(existing.post); @@ -1151,12 +1151,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + boolean hasWork = false; + Long2ObjectLinkedOpenHashMap[] buckets = this.buckets; -+ int lowestPriority = 0; -+ while (lowestPriority < MAX_PRIORITIES && !isEmpty()) { -+ Long2ObjectLinkedOpenHashMap bucket = buckets[lowestPriority]; ++ int priority = 0; ++ while (priority < MAX_PRIORITIES && !isEmpty()) { ++ Long2ObjectLinkedOpenHashMap bucket = buckets[priority]; + if (bucket.isEmpty()) { -+ lowestPriority++; -+ if (hasWork && lowestPriority <= 5) { ++ priority++; ++ if (hasWork) { + return true; + } else { + continue;