mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 02:19:19 +00:00
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2 since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList. Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2 lazy handles filter condition on iteration, so much better.
47 lines
2.6 KiB
Diff
47 lines
2.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: hayanesuru <hayanesuru@outlook.jp>
|
|
Date: Tue, 3 Jun 2025 15:41:12 +0900
|
|
Subject: [PATCH] optimize structure map
|
|
|
|
|
|
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
index 7fc5e56586f2fe8ea1a7437b42da893383878880..585765134da9d99e994e9ac250c7c757d33b3698 100644
|
|
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
@@ -77,8 +77,8 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
|
protected BlendingData blendingData;
|
|
public final Map<Heightmap.Types, Heightmap> heightmaps = Maps.newEnumMap(Heightmap.Types.class);
|
|
// Paper - rewrite chunk system
|
|
- private final Map<Structure, StructureStart> structureStarts = Maps.newHashMap();
|
|
- private final Map<Structure, LongSet> structuresRefences = Maps.newHashMap();
|
|
+ private final Map<Structure, StructureStart> structureStarts = new it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap<>(); // Leaf - optimize structure map
|
|
+ private final Map<Structure, LongSet> structuresRefences = new it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap<>(); // Leaf - optimize structure map
|
|
protected final Map<BlockPos, CompoundTag> pendingBlockEntities = Maps.newHashMap();
|
|
public final Map<BlockPos, BlockEntity> blockEntities = new Object2ObjectOpenHashMap<>();
|
|
protected final LevelHeightAccessor levelHeightAccessor;
|
|
@@ -304,7 +304,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
|
}
|
|
|
|
public Map<Structure, StructureStart> getAllStarts() {
|
|
- return Collections.unmodifiableMap(this.structureStarts);
|
|
+ return this.structureStarts; // Leaf - optimize structure map
|
|
}
|
|
|
|
public void setAllStarts(Map<Structure, StructureStart> structureStarts) {
|
|
@@ -320,13 +320,13 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
|
|
|
@Override
|
|
public void addReferenceForStructure(Structure structure, long reference) {
|
|
- this.structuresRefences.computeIfAbsent(structure, key -> new LongOpenHashSet()).add(reference);
|
|
+ this.structuresRefences.computeIfAbsent(structure, key -> new it.unimi.dsi.fastutil.longs.LongArraySet()).add(reference); // Leaf - optimize structure map
|
|
this.markUnsaved();
|
|
}
|
|
|
|
@Override
|
|
public Map<Structure, LongSet> getAllReferences() {
|
|
- return Collections.unmodifiableMap(this.structuresRefences);
|
|
+ return this.structuresRefences; // Leaf - optimize structure map
|
|
}
|
|
|
|
@Override
|