Decrease final startup memory usage

This commit is contained in:
Camotoy 2023-04-07 14:08:22 -04:00
parent 5eb8bec76e
commit 503296a9cf
4 changed files with 13 additions and 5 deletions

View File

@ -37,7 +37,7 @@ public class NbtRegistryLoader implements RegistryLoader<String, NbtMap> {
@Override
public NbtMap load(String input) {
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(GeyserImpl.getInstance().getBootstrap().getResource(input))) {
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(GeyserImpl.getInstance().getBootstrap().getResource(input), true, true)) {
return (NbtMap) nbtInputStream.readTag();
} catch (Exception e) {
throw new AssertionError("Failed to load registrations for " + input, e);

View File

@ -28,6 +28,8 @@ package org.geysermc.geyser.registry.populator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import it.unimi.dsi.fastutil.objects.*;
import org.cloudburstmc.nbt.*;
import org.cloudburstmc.protocol.bedrock.codec.v544.Bedrock_v544;
@ -84,10 +86,14 @@ public final class BlockRegistryPopulator {
})
.build();
// We can keep this strong as nothing should be garbage collected
// Safe to intern since Cloudburst NBT is immutable
Interner<NbtMap> statesInterner = Interners.newStrongInterner();
for (Map.Entry<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> palette : blockMappers.entrySet()) {
NbtList<NbtMap> blocksTag;
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(String.format("bedrock/block_palette.%s.nbt", palette.getKey().key()));
NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)))) {
NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) {
NbtMap blockPalette = (NbtMap) nbtInputStream.readTag();
blocksTag = (NbtList<NbtMap>) blockPalette.getList("blocks", NbtType.COMPOUND);
} catch (Exception e) {
@ -102,6 +108,7 @@ public final class BlockRegistryPopulator {
for (int i = 0; i < blocksTag.size(); i++) {
NbtMapBuilder builder = blocksTag.get(i).toBuilder();
builder.remove("name_hash"); // Quick workaround - was added in 1.19.20
builder.putCompound("states", statesInterner.intern((NbtMap) builder.remove("states")));
NbtMap tag = builder.build();
if (blockStateOrderedMap.containsKey(tag)) {
throw new AssertionError("Duplicate block states in Bedrock palette: " + tag);

View File

@ -172,7 +172,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
LinkedHashMap<String, Set<CommandEnumConstraint>> values = new LinkedHashMap<>();
// Is this right?
for (String s : entry.getValue()) {
values.put(s, Set.of(CommandEnumConstraint.ALLOW_ALIASES));
values.put(s, EnumSet.of(CommandEnumConstraint.ALLOW_ALIASES));
}
// Create a basic alias

View File

@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.packet.SetTitlePacket;
import lombok.Getter;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.PreferencesCache;
import org.geysermc.geyser.text.ChatColor;
import java.util.concurrent.TimeUnit;
@ -131,12 +132,12 @@ public class CooldownUtils {
int darkGrey = (int) Math.floor(10d * cooldown);
int grey = 10 - darkGrey;
StringBuilder builder = new StringBuilder("§8");
StringBuilder builder = new StringBuilder(ChatColor.DARK_GRAY);
while (darkGrey > 0) {
builder.append("˙");
darkGrey--;
}
builder.append("§7");
builder.append(ChatColor.GRAY);
while (grey > 0) {
builder.append("˙");
grey--;