[BUG 1.19.2] Something is loading the server from your mod.
GitJhopa opened this issue ยท 5 comments
Spark profiler https://spark.lucko.me/YmfKwOyw1k
sigh this stuff. Feeding Troughs are... strange.
need fix or disable config this)
I was looking at the profiler and it looks like this function java.util.stream.ReferencePipeline.findFirst() was using 4.57% which was the big thing. I don't really develop on this mod but I'll look into the code.
public static Player temptWithTroughs(TemptGoal goal, Player found, ServerLevel level) {
if (!ModuleLoader.INSTANCE.isModuleEnabled(FeedingTroughModule.class) ||
(found != null && (goal.items.test(found.getMainHandItem()) || goal.items.test(found.getOffhandItem()))))
return found;
if (!(goal.mob instanceof Animal animal) ||
!animal.canFallInLove() ||
animal.getAge() != 0)
return found;
Vec3 position = animal.position();
TroughPointer pointer = null;
boolean cached = false;
if(enableTroughCaching) {
TroughPointer candidate = TroughPointer.fromEntity(animal, goal);
if(candidate != null) {
pointer = candidate;
cached = true;
}
}
if(!cached)
pointer = level.getPoiManager().findAllClosestFirstWithType(
IS_FEEDER, p -> p.distSqr(new Vec3i(position.x, position.y, position.z)) <= range * range,
animal.blockPosition(), (int) range, PoiManager.Occupancy.ANY)
.map(Pair::getSecond)
.map(pos -> getTroughFakePlayer(level, pos, goal))
.filter(Predicates.notNull())
**.findFirst()**
.orElse(null);
if(pointer != null && pointer.exists()) {
BlockPos location = pointer.pos();
Vec3 eyesPos = goal.mob.position().add(0, goal.mob.getEyeHeight(), 0);
Vec3 targetPos = new Vec3(location.getX(), location.getY(), location.getZ()).add(0.5, 0.0625, 0.5);
BlockHitResult ray = goal.mob.level.clip(new ClipContext(eyesPos, targetPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, goal.mob));
if (ray.getType() == HitResult.Type.BLOCK && ray.getBlockPos().equals(location)) {
if(!cached)
pointer.save(animal);
return pointer.player();
}
}
// if we got here that means the cache is invalid
if(cached)
animal.getPersistentData().remove(TAG_CACHE);
return found;
}
Ok, so looking at it a bit I can see the general load-related issues. If this is going off every tick, doing a range search to find an animal of age != 0 and creating a pointer from the mob to the player would cause a lot of load.
Since I don't know much about the rest of the code, my suggestion would be to make it only go off 10 times a second instead of 20? But I could be very wrong here. The O-notation is fine, I just think that the load of this function is hard to fix.
P.S. This "findFirst()" I put asterisks around is what the profiler is saying is eating a lot of the cpu. If that can be fixed that should massively optimize the code. I might download the repo and test it, but I am fairly busy today, so I hope this in writing helps!
-Sai