mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-22 06:55:36 +01:00
Reduce memory footprint of CompoundTag
Fastutil maps are going to have a lower memory footprint - which is important because we clone chunk data after reading it for safety. So, reduce the impact of the clone on GC.
This commit is contained in:
parent
60c674b750
commit
ee1fd0844d
1 changed files with 40 additions and 2 deletions
|
@ -1,13 +1,51 @@
|
||||||
--- a/net/minecraft/nbt/CompoundTag.java
|
--- a/net/minecraft/nbt/CompoundTag.java
|
||||||
+++ b/net/minecraft/nbt/CompoundTag.java
|
+++ b/net/minecraft/nbt/CompoundTag.java
|
||||||
@@ -235,6 +235,10 @@
|
@@ -49,7 +49,7 @@
|
||||||
this.tags.put(key, NbtUtils.createUUID(value));
|
|
||||||
|
private static CompoundTag loadCompound(DataInput input, NbtAccounter tracker) throws IOException {
|
||||||
|
tracker.accountBytes(48L);
|
||||||
|
- Map<String, Tag> map = Maps.newHashMap();
|
||||||
|
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - Reduce memory footprint of CompoundTag
|
||||||
|
|
||||||
|
byte b;
|
||||||
|
while ((b = input.readByte()) != 0) {
|
||||||
|
@@ -166,7 +166,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CompoundTag() {
|
||||||
|
- this(Maps.newHashMap());
|
||||||
|
+ this(new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f)); // Paper - Reduce memory footprint of CompoundTag
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@@ -234,7 +234,11 @@
|
||||||
|
public void putUUID(String key, UUID value) {
|
||||||
|
this.tags.put(key, NbtUtils.createUUID(value));
|
||||||
|
}
|
||||||
+
|
+
|
||||||
|
|
||||||
+ /**
|
+ /**
|
||||||
+ * You must use {@link #hasUUID(String)} before or else it <b>will</b> throw an NPE.
|
+ * You must use {@link #hasUUID(String)} before or else it <b>will</b> throw an NPE.
|
||||||
+ */
|
+ */
|
||||||
public UUID getUUID(String key) {
|
public UUID getUUID(String key) {
|
||||||
return NbtUtils.loadUUID(this.get(key));
|
return NbtUtils.loadUUID(this.get(key));
|
||||||
}
|
}
|
||||||
|
@@ -477,8 +481,16 @@
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag copy() {
|
||||||
|
- Map<String, Tag> map = Maps.newHashMap(Maps.transformValues(this.tags, Tag::copy));
|
||||||
|
- return new CompoundTag(map);
|
||||||
|
+ // Paper start - Reduce memory footprint of CompoundTag
|
||||||
|
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> ret = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(this.tags.size(), 0.8f);
|
||||||
|
+ java.util.Iterator<java.util.Map.Entry<String, Tag>> iterator = (this.tags instanceof it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) ? ((it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)this.tags).object2ObjectEntrySet().fastIterator() : this.tags.entrySet().iterator();
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Map.Entry<String, Tag> entry = iterator.next();
|
||||||
|
+ ret.put(entry.getKey(), entry.getValue().copy());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return new CompoundTag(ret);
|
||||||
|
+ // Paper end - Reduce memory footprint of CompoundTag
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue