-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache blockstates and blast resistance for explosions #282
base: 1.17.x/dev
Are you sure you want to change the base?
Conversation
cache all blockstates and blast resistance
more accurate times:7.3s vs 10.0s |
@@ -62,6 +65,10 @@ | |||
// The cached mutable block position used during block traversal. | |||
private final BlockPos.Mutable cachedPos = new BlockPos.Mutable(); | |||
|
|||
private BlockPos posOrigin; | |||
//cached block and blast resistance | |||
private final HashMap<Vec3i,Pair<Float,BlockState>> blockAndBlastResCache=new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unpacking can degrade performance here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about the pair?idk,it seems better than 2 hashmap for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to replace Pair<BlockState, Float>
with this
public record BlockStateResistance(BlockState state, float resistance)
private final HashMap<BlockPos, BlockStateResistance> map = new HashMap<>();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried,it look cleaner, but it crash at runtime, mixin seems to not really like that
net.minecraft.util.crash.CrashException: Ticking entity
at net.minecraft.server.MinecraftServer.tickWorlds(MinecraftServer.java:895) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:831) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:96) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.MinecraftServer.handler$zgl000$modifiedRunLoop(MinecraftServer.java:2890) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:676) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:270) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: org.spongepowered.asm.mixin.transformer.throwables.IllegalClassLoadError: me.jellysquid.mods.lithium.mixin.world.explosions.BlockStateResistance is in a defined mixin package me.jellysquid.mods.lithium.mixin.* owned by lithium.mixins.json and cannot be referenced directly
at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:330) ~[sponge-mixin-0.9.4+mixin.0.8.2.jar:0.9.4+mixin.0.8.2]
at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:208) ~[sponge-mixin-0.9.4+mixin.0.8.2.jar:0.9.4+mixin.0.8.2]
at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:178) ~[sponge-mixin-0.9.4+mixin.0.8.2.jar:0.9.4+mixin.0.8.2]
at org.spongepowered.asm.mixin.transformer.FabricMixinTransformerProxy.transformClassBytes(FabricMixinTransformerProxy.java:23) ~[fabric-loader-0.11.6.jar:0.9.4+mixin.0.8.2]
at net.fabricmc.loader.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:162) ~[fabric-loader-0.11.6.jar:?]
at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:154) ~[fabric-loader-0.11.6.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[?:?]
at net.minecraft.world.explosion.Explosion.getBlockAndBlastRes(Explosion.java:1329) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.explosion.Explosion.traverseBlock(Explosion.java:1251) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.explosion.Explosion.performRayCast(Explosion.java:1215) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.explosion.Explosion.redirect$zfb000$collectBlocks(Explosion.java:1160) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.explosion.Explosion.collectBlocksAndDamageEntities(Explosion.java:192) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.world.ServerWorld.createExplosion(ServerWorld.java:907) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.World.createExplosion(World.java:495) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.entity.TntEntity.explode(TntEntity.java:100) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.entity.TntEntity.tick(TntEntity.java:88) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.world.ServerWorld.tickEntity(ServerWorld.java:655) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.World.tickEntity(World.java:483) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.world.ServerWorld.method_31420(ServerWorld.java:417) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.world.EntityList.forEach(EntityList.java:54) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.world.ServerWorld.tick(ServerWorld.java:392) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
at net.minecraft.server.MinecraftServer.tickWorlds(MinecraftServer.java:891) ~[minecraft-1.17.1-project-@-mapped-net.fabricmc.yarn-1.17.1+build.40-v2.jar:?]
... 6 more```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to create a class in common
package
profiling:not big improvement,like 2~3% of the explosion |
Caching the inner 3x3x3 or 5x5x5 might be a good idea. I think it is not viable to cache all blocks in the explosion range, as the outer ones will not be hit by many explosion rays, making the caching less effective. |
iirc it wasn't better, and more complex,but I will not be able to test in the next days |
cache all blockstates and blast resistance in a hashmap
Modify a lot the structure, and is probably not very clean
7.6s vs 13.1s in normal lithium:1000 tnt at 0 10 0
not very precise,I got many differents result,but it seems to be significantly faster
original idea to cache origin blocks in array by sarah