Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
optimize getChunkCount
Browse files Browse the repository at this point in the history
  • Loading branch information
404Setup committed Nov 12, 2024
1 parent 3747d07 commit 5738949
Show file tree
Hide file tree
Showing 52 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Barnaby <22575741+barnabwhy@users.noreply.github.com>
Date: Sat, 29 Jun 2024 12:06:51 +0100
Subject: [PATCH] Paper Reduce work done in CraftMapCanvas.drawImage by
limiting size of image and using System.arraycopy instead of for loops and
use bitwise operations to do bounds checks.
limiting size of image and using System.arraycopy instead of for loops and
use bitwise operations to do bounds checks.


diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java
Expand Down
41 changes: 41 additions & 0 deletions patches/server/0031-Paper-optimize-getChunkCount.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 404Setup <153366651+404Setup@users.noreply.github.com>
Date: Tue, 12 Nov 2024 15:31:47 +0800
Subject: [PATCH] Paper optimize getChunkCount

It was returning ticking chunk count instead of the intended full chunk count.
We can also directly use the size of the fullChunks collection instead of iterating all chunks.

diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index e8e9af9128e8cbdba3664f5afa3c5f56403fe70e..dc6e1258c6fdaaa3cae8d4f26f1640b8567a65d7 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -67,6 +67,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
// Folia - moved to regionised world data
// Paper start
private final ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<net.minecraft.world.level.chunk.LevelChunk> fullChunks = new ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<>();
+ public int getFullChunksCount() { return this.fullChunks.size(); }
long chunkFutureAwaitCounter;
// Paper end
// Paper start - rewrite chunk system
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index e6e83eb3974f0963916b36281b5e2ab647ae7cb8..3c022b12b5376457fd4e51499fcafc4e58d9caae 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -232,15 +232,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {

@Override
public int getChunkCount() {
- int ret = 0;
-
- for (ChunkHolder chunkHolder : ca.spottedleaf.moonrise.common.util.ChunkSystem.getVisibleChunkHolders(this.world)) {
- if (chunkHolder.getTickingChunk() != null) {
- ++ret;
- }
- }
-
- return ret;
+ return this.world.getChunkSource().getFullChunksCount();
}

@Override

0 comments on commit 5738949

Please sign in to comment.