mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-22 08:19:19 +00:00
apply a lot of patches
This commit is contained in:
@@ -21,30 +21,24 @@ import static it.unimi.dsi.fastutil.Hash.FAST_LOAD_FACTOR;
|
||||
|
||||
/**
|
||||
* Generally provides better performance over the vanilla {@link net.minecraft.world.level.chunk.HashMapPalette} when calling
|
||||
* {@link LithiumHashPalette#idFor(Object)} through using a faster backing map and reducing pointer chasing.
|
||||
* {@link LithiumHashPalette#idFor(Object, PaletteResize)} through using a faster backing map and reducing pointer chasing.
|
||||
*/
|
||||
public class LithiumHashPalette<T> implements Palette<T> {
|
||||
private static final int ABSENT_VALUE = -1;
|
||||
|
||||
private final IdMap<T> idList;
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final int indexBits;
|
||||
|
||||
private final Reference2IntOpenHashMap<T> table;
|
||||
private T[] entries;
|
||||
private int size = 0;
|
||||
|
||||
private LithiumHashPalette(IdMap<T> idList, PaletteResize<T> resizeHandler, int indexBits, T[] entries, Reference2IntOpenHashMap<T> table, int size) {
|
||||
this.idList = idList;
|
||||
this.resizeHandler = resizeHandler;
|
||||
private LithiumHashPalette(int indexBits, T[] entries, Reference2IntOpenHashMap<T> table, int size) {
|
||||
this.indexBits = indexBits;
|
||||
this.entries = entries;
|
||||
this.table = table;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResize<T> resizeHandler, List<T> list) {
|
||||
this(idList, bits, resizeHandler);
|
||||
public LithiumHashPalette(int bits, List<T> list) {
|
||||
this(bits);
|
||||
|
||||
for (T t : list) {
|
||||
this.addEntry(t);
|
||||
@@ -52,10 +46,8 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResize<T> resizeHandler) {
|
||||
this.idList = idList;
|
||||
public LithiumHashPalette(int bits) {
|
||||
this.indexBits = bits;
|
||||
this.resizeHandler = resizeHandler;
|
||||
|
||||
int capacity = 1 << bits;
|
||||
|
||||
@@ -65,11 +57,11 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int idFor(@NotNull T obj) {
|
||||
public int idFor(@NotNull T obj, @NotNull PaletteResize<T> resizeHandler) {
|
||||
int id = this.table.getInt(obj);
|
||||
|
||||
if (id == ABSENT_VALUE) {
|
||||
id = this.computeEntry(obj);
|
||||
id = this.computeEntry(obj, resizeHandler);
|
||||
}
|
||||
|
||||
return id;
|
||||
@@ -86,14 +78,14 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private int computeEntry(T obj) {
|
||||
private int computeEntry(T obj, PaletteResize<T> resizeHandler) {
|
||||
int id = this.addEntry(obj);
|
||||
|
||||
if (id >= 1 << this.indexBits) {
|
||||
if (this.resizeHandler == null) {
|
||||
if (resizeHandler == null) {
|
||||
throw new IllegalStateException("Cannot grow");
|
||||
} else {
|
||||
id = this.resizeHandler.onResize(this.indexBits + 1, obj);
|
||||
id = resizeHandler.onResize(this.indexBits + 1, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,32 +141,32 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(FriendlyByteBuf buf) {
|
||||
public void read(FriendlyByteBuf buf, @NotNull IdMap<T> idMap) {
|
||||
this.clear();
|
||||
|
||||
int entryCount = buf.readVarInt();
|
||||
|
||||
for (int i = 0; i < entryCount; ++i) {
|
||||
this.addEntry(this.idList.byIdOrThrow(buf.readVarInt()));
|
||||
this.addEntry(idMap.byIdOrThrow(buf.readVarInt()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, @NotNull IdMap<T> idMap) {
|
||||
int size = this.size;
|
||||
buf.writeVarInt(size);
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
buf.writeVarInt(this.idList.getId(this.valueFor(i)));
|
||||
buf.writeVarInt(idMap.getId(this.valueFor(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSerializedSize() {
|
||||
public int getSerializedSize(@NotNull IdMap<T> idMap) {
|
||||
int size = VarInt.getByteSize(this.size);
|
||||
|
||||
for (int i = 0; i < this.size; ++i) {
|
||||
size += VarInt.getByteSize(this.idList.getId(this.valueFor(i)));
|
||||
size += VarInt.getByteSize(idMap.getId(this.valueFor(i)));
|
||||
}
|
||||
|
||||
return size;
|
||||
@@ -186,8 +178,8 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Palette<T> copy(@NotNull PaletteResize<T> resizeHandler) {
|
||||
return new LithiumHashPalette<>(this.idList, resizeHandler, this.indexBits, this.entries.clone(), this.table.clone(), this.size);
|
||||
public @NotNull Palette<T> copy() {
|
||||
return new LithiumHashPalette<>(this.indexBits, this.entries.clone(), this.table.clone(), this.size);
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
@@ -201,7 +193,7 @@ public class LithiumHashPalette<T> implements Palette<T> {
|
||||
return Arrays.asList(copy);
|
||||
}
|
||||
|
||||
public static <A> Palette<A> create(int bits, IdMap<A> idList, PaletteResize<A> listener, List<A> list) {
|
||||
return new LithiumHashPalette<>(idList, bits, listener, list);
|
||||
public static <A> Palette<A> create(int bits, List<A> list) {
|
||||
return new LithiumHashPalette<>(bits, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,11 +216,6 @@ public class DivineConfig {
|
||||
public static int asyncEntityTrackerKeepalive = 60;
|
||||
public static int asyncEntityTrackerQueueSize = 0;
|
||||
|
||||
// Async Join Thread settings
|
||||
public static boolean asyncJoinEnabled = false;
|
||||
public static int asyncJoinThreadCount = 1;
|
||||
public static boolean asyncJoinUseVirtualThreads = false;
|
||||
|
||||
// Async chunk sending settings
|
||||
public static boolean asyncChunkSendingEnabled = true;
|
||||
public static int asyncChunkSendingMaxThreads = 1;
|
||||
@@ -233,7 +228,6 @@ public class DivineConfig {
|
||||
regionizedChunkTicking();
|
||||
asyncPathfinding();
|
||||
multithreadedTracker();
|
||||
asyncJoinSettings();
|
||||
asyncChunkSending();
|
||||
asyncMobSpawning();
|
||||
}
|
||||
@@ -327,18 +321,6 @@ public class DivineConfig {
|
||||
if (asyncEntityTrackerQueueSize <= 0) asyncEntityTrackerQueueSize = asyncEntityTrackerMaxThreads * 384;
|
||||
}
|
||||
|
||||
private static void asyncJoinSettings() {
|
||||
asyncJoinEnabled = getBoolean(ConfigCategory.ASYNC.key("join-thread.enabled"), asyncJoinEnabled,
|
||||
"Enables async join thread, which offloads player setup and connection tasks to a separate thread",
|
||||
"This can significantly improve MSPT when multiple players are joining simultaneously");
|
||||
asyncJoinThreadCount = getInt(ConfigCategory.ASYNC.key("join-thread.thread-count"), asyncJoinThreadCount,
|
||||
"Number of threads to use for async join operations");
|
||||
asyncJoinUseVirtualThreads = getBoolean(ConfigCategory.ASYNC.key("join-thread.use-virtual-threads"), asyncJoinUseVirtualThreads,
|
||||
"Whether to use virtual threads for async join operations (requires Java 21+)");
|
||||
|
||||
AsyncJoinHandler.init(asyncJoinEnabled, asyncJoinThreadCount);
|
||||
}
|
||||
|
||||
private static void asyncChunkSending() {
|
||||
asyncChunkSendingEnabled = getBoolean(ConfigCategory.ASYNC.key("chunk-sending.enable"), asyncChunkSendingEnabled,
|
||||
"Makes chunk sending asynchronous, which can significantly reduce main thread load when many players are loading chunks.");
|
||||
@@ -408,7 +390,6 @@ public class DivineConfig {
|
||||
public static boolean virtualTabCompleteScheduler = false;
|
||||
public static boolean virtualAsyncExecutor = false;
|
||||
public static boolean virtualCommandBuilderScheduler = false;
|
||||
public static boolean virtualProfileLookupPool = false;
|
||||
public static boolean virtualServerTextFilterPool = false;
|
||||
|
||||
public static void load() {
|
||||
@@ -548,8 +529,6 @@ public class DivineConfig {
|
||||
"Uses virtual threads for the MCUtil async executor.");
|
||||
virtualCommandBuilderScheduler = getBoolean(ConfigCategory.PERFORMANCE.key("virtual-threads.command-builder-scheduler"), virtualCommandBuilderScheduler,
|
||||
"Uses virtual threads for the Async Command Builder Thread Pool.");
|
||||
virtualProfileLookupPool = getBoolean(ConfigCategory.PERFORMANCE.key("virtual-threads.profile-lookup-pool"), virtualProfileLookupPool,
|
||||
"Uses virtual threads for the Profile Lookup Pool, that is used for fetching player profiles.");
|
||||
virtualServerTextFilterPool = getBoolean(ConfigCategory.PERFORMANCE.key("virtual-threads.server-text-filter-pool"), virtualServerTextFilterPool,
|
||||
"Uses virtual threads for the server text filter pool.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user