mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Decrease final startup memory usage
This commit is contained in:
parent
5eb8bec76e
commit
503296a9cf
4 changed files with 13 additions and 5 deletions
|
@ -37,7 +37,7 @@ public class NbtRegistryLoader implements RegistryLoader<String, NbtMap> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NbtMap load(String input) {
|
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();
|
return (NbtMap) nbtInputStream.readTag();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError("Failed to load registrations for " + input, e);
|
throw new AssertionError("Failed to load registrations for " + input, e);
|
||||||
|
|
|
@ -28,6 +28,8 @@ package org.geysermc.geyser.registry.populator;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.google.common.collect.ImmutableMap;
|
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 it.unimi.dsi.fastutil.objects.*;
|
||||||
import org.cloudburstmc.nbt.*;
|
import org.cloudburstmc.nbt.*;
|
||||||
import org.cloudburstmc.protocol.bedrock.codec.v544.Bedrock_v544;
|
import org.cloudburstmc.protocol.bedrock.codec.v544.Bedrock_v544;
|
||||||
|
@ -84,10 +86,14 @@ public final class BlockRegistryPopulator {
|
||||||
})
|
})
|
||||||
.build();
|
.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()) {
|
for (Map.Entry<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> palette : blockMappers.entrySet()) {
|
||||||
NbtList<NbtMap> blocksTag;
|
NbtList<NbtMap> blocksTag;
|
||||||
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(String.format("bedrock/block_palette.%s.nbt", palette.getKey().key()));
|
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();
|
NbtMap blockPalette = (NbtMap) nbtInputStream.readTag();
|
||||||
blocksTag = (NbtList<NbtMap>) blockPalette.getList("blocks", NbtType.COMPOUND);
|
blocksTag = (NbtList<NbtMap>) blockPalette.getList("blocks", NbtType.COMPOUND);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -102,6 +108,7 @@ public final class BlockRegistryPopulator {
|
||||||
for (int i = 0; i < blocksTag.size(); i++) {
|
for (int i = 0; i < blocksTag.size(); i++) {
|
||||||
NbtMapBuilder builder = blocksTag.get(i).toBuilder();
|
NbtMapBuilder builder = blocksTag.get(i).toBuilder();
|
||||||
builder.remove("name_hash"); // Quick workaround - was added in 1.19.20
|
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();
|
NbtMap tag = builder.build();
|
||||||
if (blockStateOrderedMap.containsKey(tag)) {
|
if (blockStateOrderedMap.containsKey(tag)) {
|
||||||
throw new AssertionError("Duplicate block states in Bedrock palette: " + tag);
|
throw new AssertionError("Duplicate block states in Bedrock palette: " + tag);
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
||||||
LinkedHashMap<String, Set<CommandEnumConstraint>> values = new LinkedHashMap<>();
|
LinkedHashMap<String, Set<CommandEnumConstraint>> values = new LinkedHashMap<>();
|
||||||
// Is this right?
|
// Is this right?
|
||||||
for (String s : entry.getValue()) {
|
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
|
// Create a basic alias
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.packet.SetTitlePacket;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.session.cache.PreferencesCache;
|
import org.geysermc.geyser.session.cache.PreferencesCache;
|
||||||
|
import org.geysermc.geyser.text.ChatColor;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -131,12 +132,12 @@ public class CooldownUtils {
|
||||||
|
|
||||||
int darkGrey = (int) Math.floor(10d * cooldown);
|
int darkGrey = (int) Math.floor(10d * cooldown);
|
||||||
int grey = 10 - darkGrey;
|
int grey = 10 - darkGrey;
|
||||||
StringBuilder builder = new StringBuilder("§8");
|
StringBuilder builder = new StringBuilder(ChatColor.DARK_GRAY);
|
||||||
while (darkGrey > 0) {
|
while (darkGrey > 0) {
|
||||||
builder.append("˙");
|
builder.append("˙");
|
||||||
darkGrey--;
|
darkGrey--;
|
||||||
}
|
}
|
||||||
builder.append("§7");
|
builder.append(ChatColor.GRAY);
|
||||||
while (grey > 0) {
|
while (grey > 0) {
|
||||||
builder.append("˙");
|
builder.append("˙");
|
||||||
grey--;
|
grey--;
|
||||||
|
|
Loading…
Reference in a new issue