diff options
Diffstat (limited to 'feature-patches/1051-Remove-streams-from-hot-code.patch')
-rw-r--r-- | feature-patches/1051-Remove-streams-from-hot-code.patch | 168 |
1 files changed, 88 insertions, 80 deletions
diff --git a/feature-patches/1051-Remove-streams-from-hot-code.patch b/feature-patches/1051-Remove-streams-from-hot-code.patch index 815e75e1bd..afbe9f1e4c 100644 --- a/feature-patches/1051-Remove-streams-from-hot-code.patch +++ b/feature-patches/1051-Remove-streams-from-hot-code.patch @@ -6,44 +6,50 @@ Subject: [PATCH] Remove streams from hot code Co-authored-by: Bjarne Koll <[email protected]> Co-authored-by: Spottedleaf <[email protected]> -diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java b/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java -+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/GateBehavior.java -@@ -0,0 +0,0 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> +diff --git a/net/minecraft/world/entity/ai/behavior/GateBehavior.java b/net/minecraft/world/entity/ai/behavior/GateBehavior.java +index c215d97c24e6501e1a48a76fc08bf48ff4dfe462..bd31d1cac0d022a72bd536c41d1ef811886e7068 100644 +--- a/net/minecraft/world/entity/ai/behavior/GateBehavior.java ++++ b/net/minecraft/world/entity/ai/behavior/GateBehavior.java +@@ -57,7 +57,7 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> if (this.hasRequiredMemories(entity)) { this.status = Behavior.Status.RUNNING; this.orderPolicy.apply(this.behaviors); -- this.runningPolicy.apply(this.behaviors.stream(), world, entity, time); -+ this.runningPolicy.apply(this.behaviors, world, entity, time); // Paper - Perf: Remove streams from hot code +- this.runningPolicy.apply(this.behaviors.stream(), level, entity, gameTime); ++ this.runningPolicy.apply(this.behaviors, level, entity, gameTime); // Paper - Perf: Remove streams from hot code return true; } else { return false; -@@ -0,0 +0,0 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> +@@ -66,10 +66,13 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> @Override - public final void tickOrStop(ServerLevel world, E entity, long time) { -- this.behaviors.stream().filter(task -> task.getStatus() == Behavior.Status.RUNNING).forEach(task -> task.tickOrStop(world, entity, time)); + public final void tickOrStop(ServerLevel level, E entity, long gameTime) { +- this.behaviors +- .stream() +- .filter(behavior -> behavior.getStatus() == Behavior.Status.RUNNING) +- .forEach(behavior -> behavior.tickOrStop(level, entity, gameTime)); + // Paper start - Perf: Remove streams from hot code -+ for (final BehaviorControl<? super E> task : this.behaviors) { -+ if (task.getStatus() == Behavior.Status.RUNNING) { -+ task.tickOrStop(world, entity, time); ++ for (final BehaviorControl<? super E> behavior : this.behaviors) { ++ if (behavior.getStatus() == Behavior.Status.RUNNING) { ++ behavior.tickOrStop(level, entity, gameTime); + } + } + // Paper end - Perf: Remove streams from hot code - if (this.behaviors.stream().noneMatch(task -> task.getStatus() == Behavior.Status.RUNNING)) { - this.doStop(world, entity, time); + if (this.behaviors.stream().noneMatch(behavior -> behavior.getStatus() == Behavior.Status.RUNNING)) { + this.doStop(level, entity, gameTime); } -@@ -0,0 +0,0 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> +@@ -78,11 +81,16 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> @Override - public final void doStop(ServerLevel world, E entity, long time) { + public final void doStop(ServerLevel level, E entity, long gameTime) { this.status = Behavior.Status.STOPPED; -- this.behaviors.stream().filter(task -> task.getStatus() == Behavior.Status.RUNNING).forEach(task -> task.doStop(world, entity, time)); +- this.behaviors +- .stream() +- .filter(behavior -> behavior.getStatus() == Behavior.Status.RUNNING) +- .forEach(behavior -> behavior.doStop(level, entity, gameTime)); - this.exitErasedMemories.forEach(entity.getBrain()::eraseMemory); + // Paper start - Perf: Remove streams from hot code -+ for (final BehaviorControl<? super E> task : this.behaviors) { -+ if (task.getStatus() == Behavior.Status.RUNNING) { -+ task.doStop(world, entity, time); ++ for (final BehaviorControl<? super E> behavior : this.behaviors) { ++ if (behavior.getStatus() == Behavior.Status.RUNNING) { ++ behavior.doStop(level, entity, gameTime); + } + } + for (final MemoryModuleType<?> exitErasedMemory : this.exitErasedMemories) { @@ -53,17 +59,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } @Override -@@ -0,0 +0,0 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> +@@ -116,20 +124,30 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E> public static enum RunningPolicy { RUN_ONE { + // Paper start - Perf: Remove streams from hot code @Override -- public <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time) { -- tasks.filter(task -> task.getStatus() == Behavior.Status.STOPPED).filter(task -> task.tryStart(world, entity, time)).findFirst(); -+ public <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time) { -+ for (final BehaviorControl<? super E> task : tasks) { -+ if (task.getStatus() == Behavior.Status.STOPPED && task.tryStart(world, entity, time)) { +- public <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime) { +- behaviors.filter(behavior -> behavior.getStatus() == Behavior.Status.STOPPED) +- .filter(behavior -> behavior.tryStart(level, owner, gameTime)) +- .findFirst(); ++ public <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime) { ++ for (final BehaviorControl<? super E> behavior : behaviors) { ++ if (behavior.getStatus() == Behavior.Status.STOPPED && behavior.tryStart(level, owner, gameTime)) { + break; + } + } @@ -73,28 +81,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 TRY_ALL { + // Paper start - Perf: Remove streams from hot code @Override -- public <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time) { -- tasks.filter(task -> task.getStatus() == Behavior.Status.STOPPED).forEach(task -> task.tryStart(world, entity, time)); -+ public <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time) { -+ for (final BehaviorControl<? super E> task : tasks) { -+ if (task.getStatus() == Behavior.Status.STOPPED) { -+ task.tryStart(world, entity, time); +- public <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime) { +- behaviors.filter(behavior -> behavior.getStatus() == Behavior.Status.STOPPED).forEach(behavior -> behavior.tryStart(level, owner, gameTime)); ++ public <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime) { ++ for (final BehaviorControl<? super E> behavior : behaviors) { ++ if (behavior.getStatus() == Behavior.Status.STOPPED) { ++ behavior.tryStart(level, owner, gameTime); + } + } + // Paper end - Perf: Remove streams from hot code } }; -- public abstract <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time); -+ public abstract <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> tasks, ServerLevel world, E entity, long time); // Paper - Perf: Remove streams from hot code +- public abstract <E extends LivingEntity> void apply(Stream<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime); ++ public abstract <E extends LivingEntity> void apply(ShufflingList<BehaviorControl<? super E>> behaviors, ServerLevel level, E owner, long gameTime); // Paper - Perf: Remove streams from hot code } } -diff --git a/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java b/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java -+++ b/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java -@@ -0,0 +0,0 @@ public class GossipContainer { - return this.gossips.entrySet().stream().flatMap(entry -> entry.getValue().unpack(entry.getKey())); +diff --git a/net/minecraft/world/entity/ai/gossip/GossipContainer.java b/net/minecraft/world/entity/ai/gossip/GossipContainer.java +index 2c839dc80f451c83135828a97aced1a531004bab..b74a4ce1b629d440681a1f5c026997ccaf1d0373 100644 +--- a/net/minecraft/world/entity/ai/gossip/GossipContainer.java ++++ b/net/minecraft/world/entity/ai/gossip/GossipContainer.java +@@ -59,8 +59,22 @@ public class GossipContainer { + return this.gossips.entrySet().stream().flatMap(gossip -> gossip.getValue().unpack(gossip.getKey())); } + // Paper start - Perf: Remove streams from hot code @@ -111,35 +119,35 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end - Perf: Remove streams from hot code + - private Collection<GossipContainer.GossipEntry> selectGossipsForTransfer(RandomSource random, int count) { + private Collection<GossipContainer.GossipEntry> selectGossipsForTransfer(RandomSource random, int amount) { - List<GossipContainer.GossipEntry> list = this.unpack().toList(); + List<GossipContainer.GossipEntry> list = this.decompress(); // Paper - Perf: Remove streams from hot code if (list.isEmpty()) { return Collections.emptyList(); } else { -@@ -0,0 +0,0 @@ public class GossipContainer { +@@ -145,7 +159,7 @@ public class GossipContainer { public <T> T store(DynamicOps<T> ops) { return GossipContainer.GossipEntry.LIST_CODEC - .encodeStart(ops, this.unpack().toList()) + .encodeStart(ops, this.decompress()) // Paper - Perf: Remove streams from hot code - .resultOrPartial(error -> LOGGER.warn("Failed to serialize gossips: {}", error)) + .resultOrPartial(errorMessage -> LOGGER.warn("Failed to serialize gossips: {}", errorMessage)) .orElseGet(ops::emptyList); } -@@ -0,0 +0,0 @@ public class GossipContainer { +@@ -172,12 +186,23 @@ public class GossipContainer { final Object2IntMap<GossipType> entries = new Object2IntOpenHashMap<>(); - public int weightedValue(Predicate<GossipType> gossipTypeFilter) { + public int weightedValue(Predicate<GossipType> gossipType) { - return this.entries - .object2IntEntrySet() - .stream() -- .filter(entry -> gossipTypeFilter.test(entry.getKey())) -- .mapToInt(entry -> entry.getIntValue() * entry.getKey().weight) +- .filter(gossip -> gossipType.test(gossip.getKey())) +- .mapToInt(gossip -> gossip.getIntValue() * gossip.getKey().weight) - .sum(); + // Paper start - Perf: Remove streams from hot code + int weight = 0; + for (Object2IntMap.Entry<GossipType> entry : entries.object2IntEntrySet()) { -+ if (gossipTypeFilter.test(entry.getKey())) { ++ if (gossipType.test(entry.getKey())) { + weight += entry.getIntValue() * entry.getKey().weight; + } + } @@ -155,29 +163,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end - Perf: Remove streams from hot code } - public Stream<GossipContainer.GossipEntry> unpack(UUID target) { -diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java -+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java -@@ -0,0 +0,0 @@ public class NearestItemSensor extends Sensor<Mob> { + public Stream<GossipContainer.GossipEntry> unpack(UUID identifier) { +diff --git a/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java b/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java +index 38873e56e95dc772b184e4271f7af1fb411ac9f8..09fd13e2d958da8326276c4dadf25bf488aff5ac 100644 +--- a/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java ++++ b/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java +@@ -24,13 +24,17 @@ public class NearestItemSensor extends Sensor<Mob> { @Override - protected void doTick(ServerLevel world, Mob entity) { + protected void doTick(ServerLevel level, Mob entity) { Brain<?> brain = entity.getBrain(); -- List<ItemEntity> list = world.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0, 16.0, 32.0), itemEntity -> true); -+ List<ItemEntity> list = world.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0, 16.0, 32.0), itemEntity -> itemEntity.closerThan(entity, MAX_DISTANCE_TO_WANTED_ITEM) && entity.wantsToPickUp(world, itemEntity.getItem())); // Paper - Perf: Move predicate into getEntities - list.sort(Comparator.comparingDouble(entity::distanceToSqr)); -- Optional<ItemEntity> optional = list.stream() -- .filter(itemEntity -> entity.wantsToPickUp(world, itemEntity.getItem())) -- .filter(itemEntityx -> itemEntityx.closerThan(entity, 32.0)) +- List<ItemEntity> entitiesOfClass = level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0, 16.0, 32.0), itemEntity -> true); ++ List<ItemEntity> entitiesOfClass = level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0, 16.0, 32.0), itemEntity -> itemEntity.closerThan(entity, MAX_DISTANCE_TO_WANTED_ITEM) && entity.wantsToPickUp(level, itemEntity.getItem())); // Paper - Perf: Move predicate into getEntities + entitiesOfClass.sort(Comparator.comparingDouble(entity::distanceToSqr)); +- Optional<ItemEntity> optional = entitiesOfClass.stream() +- .filter(itemEntity -> entity.wantsToPickUp(level, itemEntity.getItem())) +- .filter(itemEntity -> itemEntity.closerThan(entity, 32.0)) - .filter(entity::hasLineOfSight) - .findFirst(); - brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, optional); + // Paper start - Perf: remove streams from hot code + ItemEntity nearest = null; -+ for (ItemEntity entityItem : list) { -+ if (entity.hasLineOfSight(entityItem)) { // Paper - Perf: Move predicate into getEntities -+ nearest = entityItem; ++ for (final ItemEntity itemEntity : entitiesOfClass) { ++ if (entity.hasLineOfSight(itemEntity)) { // Paper - Perf: Move predicate into getEntities ++ nearest = itemEntity; + break; + } + } @@ -185,31 +193,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end - Perf: remove streams from hot code } } -diff --git a/src/main/java/net/minecraft/world/level/levelgen/Beardifier.java b/src/main/java/net/minecraft/world/level/levelgen/Beardifier.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/level/levelgen/Beardifier.java -+++ b/src/main/java/net/minecraft/world/level/levelgen/Beardifier.java -@@ -0,0 +0,0 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { - int j = pos.getMinBlockZ(); - ObjectList<Beardifier.Rigid> objectList = new ObjectArrayList<>(10); - ObjectList<JigsawJunction> objectList2 = new ObjectArrayList<>(32); -- world.startsForStructure(pos, structure -> structure.terrainAdaptation() != TerrainAdjustment.NONE) +diff --git a/net/minecraft/world/level/levelgen/Beardifier.java b/net/minecraft/world/level/levelgen/Beardifier.java +index 1a09da5aa1ae047a002d6779326c2a29e47d32b5..131923282c9ecbcb1d7f45a826da907c02bd2716 100644 +--- a/net/minecraft/world/level/levelgen/Beardifier.java ++++ b/net/minecraft/world/level/levelgen/Beardifier.java +@@ -35,9 +35,10 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { + int minBlockZ = chunkPos.getMinBlockZ(); + ObjectList<Beardifier.Rigid> list = new ObjectArrayList<>(10); + ObjectList<JigsawJunction> list1 = new ObjectArrayList<>(32); +- structureManager.startsForStructure(chunkPos, structure -> structure.terrainAdaptation() != TerrainAdjustment.NONE) - .forEach( -- start -> { +- structureStart -> { + // Paper start - Perf: Remove streams from hot code -+ for (net.minecraft.world.level.levelgen.structure.StructureStart start : world.startsForStructure(pos, (structure) -> { ++ for (net.minecraft.world.level.levelgen.structure.StructureStart structureStart : structureManager.startsForStructure(chunkPos, structure -> { + return structure.terrainAdaptation() != TerrainAdjustment.NONE; + })) { // Paper end - Perf: Remove streams from hot code - TerrainAdjustment terrainAdjustment = start.getStructure().terrainAdaptation(); + TerrainAdjustment terrainAdjustment = structureStart.getStructure().terrainAdaptation(); - for (StructurePiece structurePiece : start.getPieces()) { -@@ -0,0 +0,0 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { + for (StructurePiece structurePiece : structureStart.getPieces()) { +@@ -65,8 +66,7 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { } } } - } - ); + } // Paper - Perf: Remove streams from hot code - return new Beardifier(objectList.iterator(), objectList2.iterator()); + return new Beardifier(list.iterator(), list1.iterator()); } |