mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-27 19:09:22 +00:00
* Init 1.21.6
* Finish API patches
* Apply purpur patches & all paper server patches
* Apply some
* Apply all
* Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@6aafe29e 1.21.6 dev
PaperMC/Paper@ae7c74ec tweak mob goal keys, generate missing api
PaperMC/Paper@9ea1460b Revert "fix sponge-absorb deleting chest content (#12647)"
Purpur Changes:
PurpurMC/Purpur@eb0ba67d Updated Upstream (Paper)
PurpurMC/Purpur@7c6502dc Updated Upstream (Paper)
PurpurMC/Purpur@aa289e2c Updated Upstream (Paper)
PurpurMC/Purpur@b1d412fb Updated Upstream (Paper)
PurpurMC/Purpur@293e28a0 use empty registryaccess where context is not needed, closes #1676
PurpurMC/Purpur@452bb319 port PaperMC/Paper#12654, closes #1665
PurpurMC/Purpur@849bc79c register test subcommands used for debugging, closes #1675
* Fix build & diff
* Update vanilla attribute size
* [ci/skip] Forget to remove this
* Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@a24f9b20 1.21.6 dev
PaperMC/Paper@457a0a69 Bump version string and protocol version to 1.21.6 release
PaperMC/Paper@245b5473 Update base to 1.21.6
PaperMC/Paper@b28d77b3 Update Moonrise to 1.21.6
PaperMC/Paper@8318dcb7 Update DataConverter to 1.21.6-rc1
Purpur Changes:
PurpurMC/Purpur@b228e316 Updated Upstream (Paper)
PurpurMC/Purpur@d6562a57 make happy ghast takes-damage-from-water and always-drop-exp options work
PurpurMC/Purpur@08d989b6 inline import
PurpurMC/Purpur@61d7f559 Updated Upstream (Paper)
PurpurMC/Purpur@469a4de5 Merge branch 'ver/1.21.5' into ver/1.21.6
* Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@d2b1158e Set correct world access on BSL snapshots
* Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@023e6c29 Ensure waypoints are per world
PaperMC/Paper@40d5d31c Fix recursively converting JSON Text Components
* Update spigot mapping to remap reobf mapping to mojamp for plugins
* Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@1fcc4162 Implement FeatureHooks#isChunkSent for Moonrise chunk system
PaperMC/Paper@e4d7178a Implement WaypointTransmitter#isChunkVisible
PaperMC/Paper@8980ead7 Directly walk text component after converting from JSON
PaperMC/Paper@5613ed6d Provide env environment variable and copy spigots sys prop for overriding default repository
PaperMC/Paper@62b7f86d Avoid and discourage use of Maven Central as a CDN (#12689)
PaperMC/Paper@f5534cb7 [ci/skip] Run generators (#12691)
PaperMC/Paper@4781d28b Re-add Log4j Javadocs (#12693)
PaperMC/Paper@74fbcce5 Check type of Material in get/set stats (#12607)
PaperMC/Paper@4b3f967e Improve Fix MC-44654 (#12703)
PaperMC/Paper@a7dd2635 Enable spigot obfuscation support (#12695)
PaperMC/Paper@6a51c44e Cleanup Primed TNT Fix (#12704)
PaperMC/Paper@839c6a18 Fix #11169 (#12706)
PaperMC/Paper@c77d5f99 Fix MC-297591
PaperMC/Paper@219f86ee Implement chunk unload delay config option
PaperMC/Paper@e4eb69b8 Do not allow ticket level decreases to be processed asynchronously
PaperMC/Paper@71b0c768 Adds support for vanilla negative explosions (#12705)
PaperMC/Paper@3750927a [ci/skip] Fix PermissionManager#clearPermissions() docs bad wording (#12657)
PaperMC/Paper@d61a51e8 Add ItemType#getBurnDuration() (#12604)
PaperMC/Paper@29fc8532 Allow empty paths in namespaced keys (#12687)
PaperMC/Paper@4419afb9 fix: Safely handle nanosecond overflow in ClickCallback (#12686)
PaperMC/Paper@56528821 Add `isProxyEnabled` method to ServerConfiguration (#12664)
PaperMC/Paper@c0dda0ea Add `isForceDefaultGameMode` method (#12673)
PaperMC/Paper@e714de63 Fix excess slot updates
PaperMC/Paper@6d0821d2 [ci/skip] Fix docs for Spawner class and cleanup (#12710)
PaperMC/Paper@cceffe3d Release ItemType and BlockType (#12708)
PaperMC/Paper@186e9e33 Relocate CommandMap#registerServerAliases() call to after lifecycle events have been run (#12601)
PaperMC/Paper@5edcf6dd Cleanup/command dispatching (#12713)
Purpur Changes:
PurpurMC/Purpur@baa196f5 Updated Upstream (Paper)
PurpurMC/Purpur@fdd1e980 Updated Upstream (Paper)
PurpurMC/Purpur@439f15db Updated Upstream (Paper)
PurpurMC/Purpur@46a28b93 [ci/skip] update version in README
PurpurMC/Purpur@162bd288 Updated Upstream (Paper)
PurpurMC/Purpur@afcdf9bb Updated Upstream (Paper)
* fix random tick order
Signed-off-by: hayanesuru <hayanesuru@outlook.jp>
* update optimize random tick
* fix mob spawning over limit
* optimize mob spawning
* fix FastBitRadixSort memory leak
* optimize brain collections
* [ci/skip] update comments
* Revert "fix FastBitRadixSort memory leak"
This reverts commit bdea683525.
* optimize brain collections
* fix async mob spawning data race
* [ci/skip] cleanup
* remove hash lookup in optimize random tick
* Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@803baf0b Support hidden entities in Waypoints (#12715)
PaperMC/Paper@1814d8b4 build: publish to fill (#12717)
PaperMC/Paper@e454fef4 Add support for private constructors in plugin main classes (#12652)
PaperMC/Paper@d0e808f4 Move player to correct position in vehicle move packet handler
PaperMC/Paper@46b4b0b8 Improve keepalive ping system
PaperMC/Paper@38c1ddb5 Add and use FeatureHooks.getAllEntities
PaperMC/Paper@2f083acb Ensure player entity schedulers are ticked when they are dead
PaperMC/Paper@7c90c7c4 Optimise EntityScheduler ticking
PaperMC/Paper@aa6ee44a Re-add global region scheduler tick erroneously removed in last commit
PaperMC/Paper@d7510efc Fix #12722 (#12726)
PaperMC/Paper@0caf75f8 Fix #12721 (#12725)
PaperMC/Paper@bee28792 Adventure 4.23.0 (#12690)
PaperMC/Paper@692e93a9 Fix MC-299110
PaperMC/Paper@ea10fa4a Don't mutate the position of Items for MC-4 Fix (#12702)
PaperMC/Paper@aa6cd74c Remove unnecesary item check for ServerboundPlayerActionPacket RELEASE_USE_ITEM (#12668)
PaperMC/Paper@c9e89f49 Expose arrow velocity in EntityShootBowEvent for mobs (#12688)
PaperMC/Paper@7ec3174a Jump out of experimental phase
PaperMC/Paper@4e1a2555 Update try catch for command handling
PaperMC/Paper@e382e687 Fix 0 yield on explosion events
PaperMC/Paper@35b2c6ec Use dropped item for stats info (#12747)
PaperMC/Paper@bd79e20c [ci/skip] PluginManager#getPlugin and PluginManager#isPluginEnabled are case-insensitive (#12723)
Purpur Changes:
PurpurMC/Purpur@4a5974cf Updated Upstream (Paper)
PurpurMC/Purpur@3893bba0 this is important...
PurpurMC/Purpur@47e758fb Updated Upstream (Paper)
* Update PWT patch
* cleanup
* fix playermobcaps command
* fix Didn't fill chunk buffer in async chunk sending
* cleanup
* fix HurtByTargetGoal npe
* optimize collectSpawningChunks (#382)
* optimize collectSpawningChunks
* add bit set
* cleanup
* cleanup
* cleanup
* cleanup
* Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly
Paper Changes:
PaperMC/Paper@57c202e0 Allow adventure nbt codec to parse all tags
Purpur Changes:
PurpurMC/Purpur@a4776d7b Updated Upstream (Paper)
PurpurMC/Purpur@dfd8a7ad Fix phantom going at high speed when ridden (#1680)
* Fix diff
---------
Signed-off-by: hayanesuru <hayanesuru@outlook.jp>
Co-authored-by: hayanesuru <hayanesuru@outlook.jp>
342 lines
17 KiB
Diff
342 lines
17 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Mon, 14 Apr 2025 20:07:52 +0200
|
|
Subject: [PATCH] Optimise chunkUnloads
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/starlight/light/SWMRNibbleArray.java b/ca/spottedleaf/moonrise/patches/starlight/light/SWMRNibbleArray.java
|
|
index 4ca68a903e67606fc4ef0bfa9862a73797121c8b..bed3a64388bb43e47c2ba4e67f7dde5b990d9578 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/starlight/light/SWMRNibbleArray.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/starlight/light/SWMRNibbleArray.java
|
|
@@ -22,12 +22,24 @@ public final class SWMRNibbleArray {
|
|
protected static final int INIT_STATE_INIT = 2; // initialised
|
|
protected static final int INIT_STATE_HIDDEN = 3; // initialised, but conversion to Vanilla data should be treated as if NULL
|
|
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ private volatile boolean cachedIsAllZero = false;
|
|
+ private boolean cachedIsAllZeroValid = false;
|
|
+
|
|
+ private static final ThreadLocal<SaveState[]> SAVE_STATE_CACHE = ThreadLocal.withInitial(() -> new SaveState[4]);
|
|
+
|
|
public static final int ARRAY_SIZE = 16 * 16 * 16 / (8/4); // blocks / bytes per block
|
|
// this allows us to maintain only 1 byte array when we're not updating
|
|
- static final ThreadLocal<ArrayDeque<byte[]>> WORKING_BYTES_POOL = ThreadLocal.withInitial(ArrayDeque::new);
|
|
+ static final ThreadLocal<ArrayDeque<byte[]>> WORKING_BYTES_POOL = ThreadLocal.withInitial(() -> {
|
|
+ return new ArrayDeque<>(8); // Limit pool size to avoid memory leaks
|
|
+ });
|
|
+ // Leaf end - Optimize chunkUnload
|
|
|
|
private static byte[] allocateBytes() {
|
|
- final byte[] inPool = WORKING_BYTES_POOL.get().pollFirst();
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ final ArrayDeque<byte[]> queue = WORKING_BYTES_POOL.get();
|
|
+ final byte[] inPool = queue.pollFirst();
|
|
+ // Leaf end - Optimize chunkUnload
|
|
if (inPool != null) {
|
|
return inPool;
|
|
}
|
|
@@ -36,7 +48,12 @@ public final class SWMRNibbleArray {
|
|
}
|
|
|
|
private static void freeBytes(final byte[] bytes) {
|
|
- WORKING_BYTES_POOL.get().addFirst(bytes);
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ final ArrayDeque<byte[]> queue = WORKING_BYTES_POOL.get();
|
|
+ if (queue.size() < 8) { // Limit pool size to prevent memory leaks
|
|
+ queue.addFirst(bytes);
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
}
|
|
|
|
public static SWMRNibbleArray fromVanilla(final DataLayer nibble) {
|
|
@@ -131,15 +148,44 @@ public final class SWMRNibbleArray {
|
|
public SaveState getSaveState() {
|
|
synchronized (this) {
|
|
final int state = this.stateVisible;
|
|
- final byte[] data = this.storageVisible;
|
|
if (state == INIT_STATE_NULL) {
|
|
return null;
|
|
}
|
|
if (state == INIT_STATE_UNINIT) {
|
|
- return new SaveState(null, state);
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ // Use array-based cache instead of WeakHashMap
|
|
+ SaveState[] cache = SAVE_STATE_CACHE.get();
|
|
+ SaveState cachedState = cache[INIT_STATE_UNINIT];
|
|
+ if (cachedState == null) {
|
|
+ cachedState = new SaveState(null, state);
|
|
+ cache[INIT_STATE_UNINIT] = cachedState;
|
|
+ }
|
|
+ return cachedState;
|
|
+ }
|
|
+
|
|
+ // Check if we need to test for all zeros
|
|
+ final byte[] data = this.storageVisible;
|
|
+ boolean zero;
|
|
+ if (cachedIsAllZeroValid) {
|
|
+ zero = cachedIsAllZero;
|
|
+ } else {
|
|
+ zero = isAllZero(data);
|
|
+ cachedIsAllZero = zero;
|
|
+ cachedIsAllZeroValid = true;
|
|
}
|
|
- final boolean zero = isAllZero(data);
|
|
if (zero) {
|
|
+ // Use array-based cache instead of WeakHashMap
|
|
+ SaveState[] cache = SAVE_STATE_CACHE.get();
|
|
+ int cacheKey = state == INIT_STATE_INIT ? INIT_STATE_UNINIT : -1;
|
|
+ if (cacheKey >= 0) {
|
|
+ SaveState cachedState = cache[cacheKey];
|
|
+ if (cachedState == null) {
|
|
+ cachedState = new SaveState(null, cacheKey);
|
|
+ cache[cacheKey] = cachedState;
|
|
+ }
|
|
+ return cachedState;
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
return state == INIT_STATE_INIT ? new SaveState(null, INIT_STATE_UNINIT) : null;
|
|
} else {
|
|
return new SaveState(data.clone(), state);
|
|
@@ -148,17 +194,28 @@ public final class SWMRNibbleArray {
|
|
}
|
|
|
|
protected static boolean isAllZero(final byte[] data) {
|
|
- for (int i = 0; i < (ARRAY_SIZE >>> 4); ++i) {
|
|
- byte whole = data[i << 4];
|
|
-
|
|
- for (int k = 1; k < (1 << 4); ++k) {
|
|
- whole |= data[(i << 4) | k];
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ // Check in 8-byte chunks
|
|
+ final int longLength = ARRAY_SIZE >>> 3;
|
|
+ for (int i = 0; i < longLength; i++) {
|
|
+ long value = 0;
|
|
+ final int baseIndex = i << 3;
|
|
+ // Combine 8 bytes into a long
|
|
+ for (int j = 0; j < 8; j++) {
|
|
+ value |= ((long) (data[baseIndex + j] & 0xFF)) << (j << 3);
|
|
+ }
|
|
+ if (value != 0) {
|
|
+ return false;
|
|
}
|
|
+ }
|
|
|
|
- if (whole != 0) {
|
|
+ // Check remaining bytes
|
|
+ for (int i = longLength << 3; i < ARRAY_SIZE; i++) {
|
|
+ if (data[i] != 0) {
|
|
return false;
|
|
}
|
|
}
|
|
+ // Leaf end - Optimize chunkUnload
|
|
|
|
return true;
|
|
}
|
|
@@ -349,6 +406,7 @@ public final class SWMRNibbleArray {
|
|
}
|
|
this.updatingDirty = false;
|
|
this.stateVisible = this.stateUpdating;
|
|
+ this.cachedIsAllZeroValid = false; // Leaf - Optimize chunkUnload - Invalidate cache on update
|
|
}
|
|
|
|
return true;
|
|
@@ -424,7 +482,16 @@ public final class SWMRNibbleArray {
|
|
final int shift = (index & 1) << 2;
|
|
final int i = index >>> 1;
|
|
|
|
- this.storageUpdating[i] = (byte)((this.storageUpdating[i] & (0xF0 >>> shift)) | (value << shift));
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ byte oldValue = this.storageUpdating[i];
|
|
+ byte newValue = (byte)((oldValue & (0xF0 >>> shift)) | (value << shift));
|
|
+
|
|
+ // Only invalidate cache if the value actually changes
|
|
+ if (oldValue != newValue) {
|
|
+ this.storageUpdating[i] = newValue;
|
|
+ this.cachedIsAllZeroValid = false;
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
}
|
|
|
|
public static final class SaveState {
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
index 4d06df242ab73411bdefc4770e131b27a6ea668a..fb936344ba363490f2255682678f08e219fdec3d 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -24,6 +24,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
private boolean isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
|
|
public final PalettedContainer<BlockState> states;
|
|
private PalettedContainer<Holder<Biome>> biomes; // CraftBukkit - read/write
|
|
+ private boolean modified = false; // Leaf - Optimize chunkUnload
|
|
|
|
// Paper start - block counting
|
|
private static final it.unimi.dsi.fastutil.shorts.ShortArrayList FULL_LIST = new it.unimi.dsi.fastutil.shorts.ShortArrayList(16*16*16);
|
|
@@ -135,6 +136,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
// Paper end - block counting
|
|
|
|
public BlockState setBlockState(int x, int y, int z, BlockState state, boolean useLocks) {
|
|
+ this.modified = true; // Leaf - Optimize chunkUnload
|
|
BlockState blockState;
|
|
if (useLocks) {
|
|
blockState = this.states.getAndSet(x, y, z, state);
|
|
@@ -328,7 +330,32 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
this.biomes = palettedContainer;
|
|
}
|
|
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ private LevelChunkSection(short nonEmptyBlockCount, short tickingBlockCount, short tickingFluidCount,
|
|
+ PalettedContainer<BlockState> states, PalettedContainer<Holder<Biome>> biomes) {
|
|
+ this.nonEmptyBlockCount = nonEmptyBlockCount;
|
|
+ this.tickingBlockCount = tickingBlockCount;
|
|
+ this.tickingFluidCount = tickingFluidCount;
|
|
+ this.states = states;
|
|
+ this.biomes = biomes;
|
|
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
+
|
|
public LevelChunkSection copy() {
|
|
+ // Leaf - Optimize chunkUnload
|
|
+ // If the section hasn't been modified and no random ticking blocks/fluids,
|
|
+ // return a lightweight copy that shares palette data
|
|
+ if (!this.modified && this.tickingBlockCount == 0 && this.tickingFluidCount == 0) {
|
|
+ return new LevelChunkSection(
|
|
+ this.nonEmptyBlockCount,
|
|
+ this.tickingBlockCount,
|
|
+ this.tickingFluidCount,
|
|
+ this.states, // Share reference instead of copying
|
|
+ this.biomes // Share reference instead of copying
|
|
+ );
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
return new LevelChunkSection(this);
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
|
index ab1fc7ca0639f9e71933f623258bb8d123988262..781f9470dc0115a464ce4711aecafb0f11a016b7 100644
|
|
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
|
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
|
@@ -495,14 +495,16 @@ public record SerializableChunkData(
|
|
throw new IllegalArgumentException("Chunk can't be serialized: " + chunk);
|
|
} else {
|
|
ChunkPos pos = chunk.getPos();
|
|
- List<SerializableChunkData.SectionData> list = new ArrayList<>(); final List<SerializableChunkData.SectionData> sectionsList = list; // Paper - starlight - OBFHELPER
|
|
- LevelChunkSection[] sections = chunk.getSections();
|
|
- LevelLightEngine lightEngine = level.getChunkSource().getLightEngine();
|
|
|
|
// Paper start - starlight
|
|
final int minLightSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinLightSection(level);
|
|
final int maxLightSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxLightSection(level);
|
|
final int minBlockSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(level);
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ // Pre-allocate with correct capacity to avoid resizing
|
|
+ final int expectedSectionCount = maxLightSection - minLightSection + 1;
|
|
+ List<SerializableChunkData.SectionData> list = new ArrayList<>(expectedSectionCount);
|
|
+ // Leaf end - Optimize chunkUnload
|
|
|
|
final LevelChunkSection[] chunkSections = chunk.getSections();
|
|
final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] blockNibbles = ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)chunk).starlight$getBlockNibbles();
|
|
@@ -520,10 +522,20 @@ public record SerializableChunkData(
|
|
continue;
|
|
}
|
|
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ DataLayer blockDataLayer = null;
|
|
+ if (blockNibble != null && blockNibble.data != null) {
|
|
+ blockDataLayer = new DataLayer(blockNibble.data);
|
|
+ }
|
|
+
|
|
+ DataLayer skyDataLayer = null;
|
|
+ if (skyNibble != null && skyNibble.data != null) {
|
|
+ skyDataLayer = new DataLayer(skyNibble.data);
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
+
|
|
final SerializableChunkData.SectionData sectionData = new SerializableChunkData.SectionData(
|
|
- lightSection, chunkSection,
|
|
- blockNibble == null ? null : (blockNibble.data == null ? null : new DataLayer(blockNibble.data)),
|
|
- skyNibble == null ? null : (skyNibble.data == null ? null : new DataLayer(skyNibble.data))
|
|
+ lightSection, chunkSection, blockDataLayer, skyDataLayer // Leaf - Optimize chunkUnload
|
|
);
|
|
|
|
if (blockNibble != null) {
|
|
@@ -534,12 +546,16 @@ public record SerializableChunkData(
|
|
((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$setSkyLightState(skyNibble.state);
|
|
}
|
|
|
|
- sectionsList.add(sectionData);
|
|
+ list.add(sectionData); // Leaf - Optimize chunkUnload
|
|
}
|
|
// Paper end - starlight
|
|
|
|
- List<CompoundTag> list1 = new ArrayList<>(chunk.getBlockEntitiesPos().size());
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ // Pre-allocate block entities list with exact size needed
|
|
+ final int blockEntityCount = chunk.getBlockEntitiesPos().size();
|
|
+ List<CompoundTag> list1 = blockEntityCount > 0 ? new ArrayList<>(blockEntityCount) : java.util.Collections.emptyList();
|
|
|
|
+ if (blockEntityCount > 0) // Leaf - Optimize chunkUnload
|
|
for (BlockPos blockPos : chunk.getBlockEntitiesPos()) {
|
|
CompoundTag blockEntityNbtForSaving = chunk.getBlockEntityNbtForSaving(blockPos, level.registryAccess());
|
|
if (blockEntityNbtForSaving != null) {
|
|
@@ -547,15 +563,27 @@ public record SerializableChunkData(
|
|
}
|
|
}
|
|
|
|
- List<CompoundTag> list2 = new ArrayList<>();
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ // For entities, use an initial estimated capacity if it's a ProtoChunk
|
|
+ List<CompoundTag> list2;
|
|
long[] longs = null;
|
|
if (chunk.getPersistedStatus().getChunkType() == ChunkType.PROTOCHUNK) {
|
|
ProtoChunk protoChunk = (ProtoChunk)chunk;
|
|
- list2.addAll(protoChunk.getEntities());
|
|
+ // Leaf start - Optimize chunkUnload
|
|
+ int entitySize = protoChunk.getEntities().size();
|
|
+ if (entitySize > 0) {
|
|
+ list2 = new ArrayList<>(Math.max(16, entitySize));
|
|
+ list2.addAll(protoChunk.getEntities());
|
|
+ } else {
|
|
+ list2 = java.util.Collections.emptyList();
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload
|
|
CarvingMask carvingMask = protoChunk.getCarvingMask();
|
|
if (carvingMask != null) {
|
|
longs = carvingMask.toArray();
|
|
}
|
|
+ } else {
|
|
+ list2 = java.util.Collections.emptyList(); // Leaf - Optimize chunkUnload
|
|
}
|
|
|
|
Map<Heightmap.Types, long[]> map = new EnumMap<>(Heightmap.Types.class);
|
|
@@ -563,14 +591,26 @@ public record SerializableChunkData(
|
|
for (Entry<Heightmap.Types, Heightmap> entry : chunk.getHeightmaps()) {
|
|
if (chunk.getPersistedStatus().heightmapsAfter().contains(entry.getKey())) {
|
|
long[] rawData = entry.getValue().getRawData();
|
|
- map.put(entry.getKey(), (long[])rawData.clone());
|
|
+ map.put(entry.getKey(), Arrays.copyOf(rawData, rawData.length)); // Leaf - Optimize chunkUnload
|
|
}
|
|
}
|
|
|
|
ChunkAccess.PackedTicks ticksForSerialization = chunk.getTicksForSerialization(level.getGameTime());
|
|
- ShortList[] lists = Arrays.stream(chunk.getPostProcessing())
|
|
- .map(list3 -> list3 != null ? new ShortArrayList(list3) : null)
|
|
- .toArray(ShortList[]::new);
|
|
+ // Leaf start - Optimize chunkUnload - remove stream
|
|
+ ShortList[] postProcessing = chunk.getPostProcessing();
|
|
+ ShortList[] lists = new ShortList[postProcessing.length];
|
|
+ for (int i = 0; i < postProcessing.length; i++) {
|
|
+ ShortList source = postProcessing[i];
|
|
+ // Only create a new list if there's actual data to copy
|
|
+ if (source != null) {
|
|
+ int size = source.size();
|
|
+ if (size > 0) {
|
|
+ lists[i] = new ShortArrayList(size);
|
|
+ lists[i].addAll(source);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Optimize chunkUnload - remove stream
|
|
CompoundTag compoundTag = packStructureData(
|
|
StructurePieceSerializationContext.fromLevel(level), pos, chunk.getAllStarts(), chunk.getAllReferences()
|
|
);
|