Skip to content

Commit

Permalink
- 更新配置文件。
Browse files Browse the repository at this point in the history
- 新增原版的区块 TileEntity 状态判断优化。
- 新增原版的区块 TileEntity 队列数据结构优化。
- 新增 Forge 的 ForgeChunkManager#getPersistentChunksIterableFor 优化。
- 新增 Botania 的数个方块实体优化。
- 改进 IC2 的 MixinGridUpdater 的计算速度。
- 修复 IC2 的 MixinReflectionUtil 不起作用的问题。
- 新增服务端线程优先级优化。
  • Loading branch information
KasumiNova committed Oct 30, 2024
1 parent 6112430 commit 6f07a35
Show file tree
Hide file tree
Showing 28 changed files with 709 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public static class Container {
@Config.Name("ContainerUnloadTileEntityFixes")
public boolean containerTileEntityFixes = false;

@Config.Comment("Restricts the player from interacting with the world's blocks when the player opens any container interface (except the player inventory).")
@Config.Name("ContainerInteractRestriction")
public boolean containerInteract = false;

}

public static class AdvancedRocketry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ public static class Vanilla {
})
@Config.RequiresMcRestart
@Config.Name("ChunkTileEntityMapImprovements")
public boolean blockPos2ValueMap = false;
public boolean chunkTEMap = false;

@Config.Comment("(Client/Server Performance | Experimental) Cache the TileEntity state of the IBlockState in a chunk to improve performance.")
@Config.RequiresMcRestart
@Config.Name("ChunkTileEntityCache")
public boolean chunkTECache = false;

@Config.Comment("(Client/Server Performance) Improving Chunk Performance with Improved Data Structures.")
@Config.RequiresMcRestart
@Config.Name("ChunkTileEntityQueueImprovements")
public boolean chunkTEQueue = true;

@Config.Comment("(Server Performance) Improving the performance of ClassInheritanceMultiMap (up to ~40%).")
@Config.RequiresMcRestart
Expand Down Expand Up @@ -202,12 +212,12 @@ public static class Vanilla {
public boolean nbtPrimitiveConstantsPool = true;

@Config.Comment({
"(Client/Server Performance) Asynchronous loading of ItemStack's Capability to improve performance.",
"(Client/Server Performance | Experimental) Asynchronous loading of ItemStack's Capability to improve performance.",
"Conflict with CensoredASM's `delayItemStackCapabilityInit` option."
})
@Config.RequiresMcRestart
@Config.Name("AsyncItemStackCapabilityInit")
public boolean asyncItemStackCapabilityInit = true;
public boolean asyncItemStackCapabilityInit = false;

@Config.Comment("(Client/Server Performance | Experimental) Replaces the internal default ArrayList of NonNullList with an ObjectArrayList (may not work).")
@Config.RequiresMcRestart
Expand Down Expand Up @@ -246,8 +256,8 @@ public static class Vanilla {
public boolean resourceExistStateCache = true;

@Config.Comment({
"(Client/Server Performance) Use parallelStream to handle randomTick operations on world blocks to improve performance in more player environments,",
"possibly affecting the random logic of the original game."
"(Client/Server Performance) Use parallelStream to handle randomTick operations on world blocks to improve performance in more player environments.",
"Note: Possibly affecting the random logic of the original game."
})
@Config.RequiresMcRestart
@Config.Name("ParallelRandomBlockTicker")
Expand Down Expand Up @@ -324,6 +334,11 @@ public static class Forge {
@Config.Name("ASMDataTableCPUUsageImprovements")
public boolean asmDataTable = false;

@Config.Comment("(Client/Server Performance) ChunkManager optimisation, improves performance in more player environments.")
@Config.RequiresMcRestart
@Config.Name("ChunkManager")
public boolean chunkManager = true;

@Config.Comment({
"(Client Performance | Experimental) Deduplicate unpackedData array to optimise memory usage, with significant optimisation for some mods.",
"Works in most cases, but may cause rendering issues with models in some mods."
Expand Down Expand Up @@ -432,6 +447,15 @@ public static class Botania {
@Config.Name("SparkEntityImprovements")
public boolean sparkImprovements = false;

@Config.Comment("(Server Performance) Improvements to the way Alf Portals work to slightly improve performance.")
public boolean alfPortalImprovements = true;

@Config.Comment("(Server Performance) Improvements to the way Pylons work to slightly improve performance.")
public boolean pylonImprovements = true;

@Config.Comment("(Server Performance) Improvements to the way Rune Altars work to slightly improve performance.")
public boolean runeAltarImprovements = true;

@Config.Comment({
"What is the maximum working interval of the sparks? They will eventually be accelerated to 1 tick.",
"Only works if SparkEntityImprovements is enabled."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package github.kasuminova.stellarcore.common.handler;


import github.kasuminova.stellarcore.common.integration.ftblib.FTBLibInvUtilsQueue;
import github.kasuminova.stellarcore.common.integration.ftbquests.FTBQInvListener;
import github.kasuminova.stellarcore.common.mod.Mods;
import github.kasuminova.stellarcore.common.util.StellarLog;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
Expand All @@ -15,7 +16,6 @@ public class StellarCoreTickHandler {
@SubscribeEvent
public static void onServerTick(final TickEvent.ServerTickEvent event) {
if (event.side.isClient()) {
// if (event.side.isClient() || event.phase != TickEvent.Phase.END) {
return;
}
tickExisted++;
Expand All @@ -26,15 +26,27 @@ public static void onServerTick(final TickEvent.ServerTickEvent event) {
if (Mods.FTBQ.loaded()) {
detectFTBQTasks();
}

updateServerThreadPriority();
}

private static void updateServerThreadPriority() {
final Thread current = Thread.currentThread();
if (FMLCommonHandler.instance().getMinecraftServerInstance().isCallingFromMinecraftThread()) {
if (current.getPriority() != Thread.MAX_PRIORITY) {
current.setPriority(Thread.MAX_PRIORITY);
StellarLog.LOG.info("[StellarCore] Set server thread priority to MAX.");
}
}
}

@Optional.Method(modid = "ftblib")
protected static void updatePlayerInv() {
private static void updatePlayerInv() {
FTBLibInvUtilsQueue.INSTANCE.updateAll();
}

@Optional.Method(modid = "ftbquests")
protected static void detectFTBQTasks() {
private static void detectFTBQTasks() {
if (tickExisted % 60 == 0) {
FTBQInvListener.INSTANCE.detect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public boolean join() {
releaseJoinLock();
// If we cannot acquire LoadLock, wait for the another thread to finish load.
awaitLoadComplete();

target.stellar_core$joinCapInit();
}
} else {
run();
Expand Down Expand Up @@ -137,11 +139,9 @@ private void releaseLoadLock() {
}

private void awaitLoadComplete() {
while (true) {
while (loadLock.isLocked()) {
// Wait for the another thread finish
if (!loadLock.isLocked()) {
break;
}
Thread.yield();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package github.kasuminova.stellarcore.common.util;

import com.google.common.collect.Iterators;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.util.math.BlockPos;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

public class BlockPosSet implements Set<BlockPos> {

protected final LongSet internal = new LongOpenHashSet();

@Override
public int size() {
return internal.size();
}

@Override
public boolean isEmpty() {
return internal.isEmpty();
}

@Override
public boolean contains(final Object o) {
if (o instanceof BlockPos) {
return internal.contains(((BlockPos) o).toLong());
}
return false;
}

@Nonnull
@Override
public Iterator<BlockPos> iterator() {
return Iterators.transform(internal.iterator(), BlockPos::fromLong);
}

@Nonnull
@Override
public BlockPos[] toArray() {
final BlockPos[] arr = new BlockPos[internal.size()];
final LongIterator it = internal.iterator();
int i = 0;
while (it.hasNext()) {
arr[i] = BlockPos.fromLong(it.nextLong());
i++;
}
return arr;
}

@Nonnull
@Override
@SuppressWarnings("unchecked")
public <T> T[] toArray(final T[] a) {
if (a.length < internal.size()) {
return (T[]) toArray();
}
final LongIterator it = internal.iterator();
int i = 0;
while (it.hasNext()) {
a[i] = (T) BlockPos.fromLong(it.nextLong());
i++;
}
return a;
}

@Override
public boolean add(final BlockPos pos) {
return internal.add(pos.toLong());
}

@Override
public boolean remove(final Object o) {
if (o instanceof BlockPos) {
return internal.remove(((BlockPos) o).toLong());
}
return false;
}

@Override
public boolean containsAll(final Collection<?> c) {
for (final Object o : c) {
if (!contains(o)) {
return false;
}
}
return true;
}

@Override
public boolean addAll(final Collection<? extends BlockPos> c) {
for (final BlockPos pos : c) {
add(pos);
}
return !c.isEmpty();
}

@Override
public boolean retainAll(final Collection<?> c) {
boolean modified = false;
Iterator<BlockPos> it = iterator();
while (it.hasNext()) {
if (!c.contains(it.next())) {
it.remove();
modified = true;
}
}
return modified;
}

@Override
public boolean removeAll(final Collection<?> c) {
boolean modified = false;
for (final Object o : c) {
modified = remove(o);
}
return modified;
}

@Override
public void clear() {
internal.clear();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.profiler.Profiler;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
Expand All @@ -22,7 +21,7 @@ public class ParallelRandomBlockTicker {

public static final ParallelRandomBlockTicker INSTANCE = new ParallelRandomBlockTicker();

private final Queue<Tuple<Chunk, List<TickData>>> enqueuedChunks = new MpmcUnboundedXaddArrayQueue<>(1000);
private final Queue<ChunkData> enqueuedChunks = new MpmcUnboundedXaddArrayQueue<>(1000);

private World currentWorld = null;
private Random currentRand = null;
Expand All @@ -32,11 +31,11 @@ private ParallelRandomBlockTicker() {
}

public void enqueueChunk(final Chunk chunk, final List<TickData> data) {
enqueuedChunks.offer(new Tuple<>(chunk, data));
enqueuedChunks.offer(new ChunkData(chunk, data));
}

public void execute(final World world, final Random rand, final Profiler profiler, final int randomTickSpeed) {
Queue<Tuple<Chunk, List<TickData>>> enqueuedChunks = this.enqueuedChunks;
public void execute(final World world, final Random rand, final Profiler profiler) {
Queue<ChunkData> enqueuedChunks = this.enqueuedChunks;
if (enqueuedChunks.isEmpty()) {
return;
}
Expand All @@ -51,11 +50,11 @@ public void execute(final World world, final Random rand, final Profiler profile

IntStream stream = parallel ? IntStream.range(0, concurrency).parallel() : IntStream.range(0, concurrency);
stream.forEach(i -> {
Tuple<Chunk, List<TickData>> data;
ChunkData data;
while ((data = enqueuedChunks.poll()) != null) {
List<RandomTickTask> collectedData = new ObjectArrayList<>();
for (final TickData tickData : data.getSecond()) {
List<RandomTickTask> tasks = getRandomTickData(data.getFirst(), tickData);
for (final TickData tickData : data.data()) {
List<RandomTickTask> tasks = getRandomTickData(data.chunk(), tickData);
if (tasks.isEmpty()) {
continue;
}
Expand Down Expand Up @@ -119,6 +118,10 @@ private void executeTask(List<RandomTickTask> tickDataList) {
profiler.endSection();
}

@Desugar
public record ChunkData(Chunk chunk, List<TickData> data) {
}

@Desugar
public record TickData(ExtendedBlockStorage blockStorage, IntList lcgList) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
addMixinCFG("mixins.stellar_core_minecraft_blockfaceuv.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.blockFaceUVsCanonicalization);
addMixinCFG("mixins.stellar_core_minecraft_blockpart.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.blockPartDataStructure);
addMixinCFG("mixins.stellar_core_minecraft_blockstateimpl.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.blockStateImplementationHashCodeCache);
addMixinCFG("mixins.stellar_core_minecraft_chunk.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.blockPos2ValueMap);
addMixinCFG("mixins.stellar_core_minecraft_chunktecache.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.chunkTECache);
addMixinCFG("mixins.stellar_core_minecraft_chunktemap.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.chunkTEMap);
addMixinCFG("mixins.stellar_core_minecraft_chunktequeue.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.chunkTEQueue);
addMixinCFG("mixins.stellar_core_minecraft_classmultimap.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.classMultiMap);
addMixinCFG("mixins.stellar_core_minecraft_entitytracker.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.entitytracker);
addMixinCFG("mixins.stellar_core_minecraft_itemstack_cap.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.asyncItemStackCapabilityInit && !(CensoredASMCompat.isPresent() && CensoredASMCompat.checkDelayItemStackCapInitEnabled()));
addMixinCFG("mixins.stellar_core_minecraft_longnbtkiller.json", () -> StellarCoreConfig.BUG_FIXES.vanilla.longNBTKiller);
addMixinCFG("mixins.stellar_core_minecraft_modelblock.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.modelBlockStringCanonicalization && CensoredASMCompat.isPresent());
addMixinCFG("mixins.stellar_core_minecraft_nbtmaplist.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.nbtTag && !(CensoredASMCompat.isPresent() && CensoredASMCompat.checkNBTMapModified()));
addMixinCFG("mixins.stellar_core_minecraft_nbtpool.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.nbtPrimitiveConstantsPool);
addMixinCFG("mixins.stellar_core_minecraft_nethandlerplayserver.json");
addMixinCFG("mixins.stellar_core_minecraft_nethandlerplayserver.json", () -> StellarCoreConfig.BUG_FIXES.container.containerInteract);
addMixinCFG("mixins.stellar_core_minecraft_nnlist.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.nonNullList);
addMixinCFG("mixins.stellar_core_minecraft_noglerror.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.noGlError);
addMixinCFG("mixins.stellar_core_minecraft_property.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.propertyEnumHashCodeCache);
Expand All @@ -57,6 +59,7 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
addMixinCFG("mixins.stellar_core_forge_bakedquad.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_bakedquad_vertexdata.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadVertexDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_capability.json", () -> StellarCoreConfig.PERFORMANCE.forge.deallocateEmptyCapabilityNBT);
addMixinCFG("mixins.stellar_core_forge_chunkmanager.json", () -> StellarCoreConfig.PERFORMANCE.forge.chunkManager);
addMixinCFG("mixins.stellar_core_forge_modelloader.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoader);
addMixinCFG("mixins.stellar_core_forge_registry.json", () -> StellarCoreConfig.FEATURES.vanilla.forgeRegistryRemoveList.length > 0);
addMixinCFG("mixins.stellar_core_hudcaching.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.hudCaching);
Expand Down
Loading

0 comments on commit 6f07a35

Please sign in to comment.