9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-27 19:09:22 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0148-Remove-stream-in-GolemSensor.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

32 lines
1.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Remove stream in GolemSensor
Stream operations in GolemSensor is really expensive and takes
up 80% time per method call.
Before: 192ms
After: 17ms
diff --git a/net/minecraft/world/entity/ai/sensing/GolemSensor.java b/net/minecraft/world/entity/ai/sensing/GolemSensor.java
index 84d9e2a43adbabda8401e8ad8dd8d87f7dbeeea7..ed277d93254a30a817dd8246539c292240dc9669 100644
--- a/net/minecraft/world/entity/ai/sensing/GolemSensor.java
+++ b/net/minecraft/world/entity/ai/sensing/GolemSensor.java
@@ -34,7 +34,15 @@ public class GolemSensor extends Sensor<LivingEntity> {
public static void checkForNearbyGolem(LivingEntity livingEntity) {
Optional<List<LivingEntity>> memory = livingEntity.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES);
if (!memory.isEmpty()) {
- boolean flag = memory.get().stream().anyMatch(entity -> entity.getType().equals(EntityType.IRON_GOLEM));
+ // Leaf start - Remove stream in GolemSensor
+ boolean flag = false;
+ for (LivingEntity entity : memory.get()) {
+ if (entity.getType().equals(EntityType.IRON_GOLEM)) {
+ flag = true;
+ break;
+ }
+ }
+ // Leaf end - Remove stream in GolemSensor
if (flag) {
golemDetected(livingEntity);
}