mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-28 11:29:11 +00:00
Temporarily drop function execution result caching
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
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] Cache function execution result
|
||||
|
||||
|
||||
diff --git a/net/minecraft/commands/arguments/EntityArgument.java b/net/minecraft/commands/arguments/EntityArgument.java
|
||||
index 8f6a1788b5ca396b79a638955fc6a6b3a276337f..4acf68e42a9644612608c8521020a989cbdea4a9 100644
|
||||
--- a/net/minecraft/commands/arguments/EntityArgument.java
|
||||
+++ b/net/minecraft/commands/arguments/EntityArgument.java
|
||||
@@ -65,6 +65,37 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
||||
}
|
||||
}
|
||||
|
||||
+ // Leaf start - Cache function getEntity calls
|
||||
+ public static final java.util.Map<String, Collection<? extends Entity>> TICK_ENTITY_CACHE = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
+ public static Collection<? extends Entity> getOptionalEntitiesCachedAs(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||
+ if (!(context.getSource().source instanceof net.minecraft.server.MinecraftServer)) return getOptionalEntities(context, name);
|
||||
+ EntitySelector selector = context.getArgument(name, EntitySelector.class);
|
||||
+ List<com.mojang.brigadier.context.ParsedCommandNode<CommandSourceStack>> nodes = context.getNodes();
|
||||
+ int idxStart = nodes.get(1).getRange().getStart();
|
||||
+ int idxEnd = nodes.get(2).getRange().getEnd();
|
||||
+ String selectorString = context.getInput().substring(idxStart, idxEnd);
|
||||
+ Collection<? extends Entity> entities = TICK_ENTITY_CACHE.get(selectorString);
|
||||
+ if (entities == null) {
|
||||
+ entities = selector.findEntities(context.getSource());
|
||||
+ TICK_ENTITY_CACHE.put(selectorString, entities);
|
||||
+ }
|
||||
+ return entities;
|
||||
+ }
|
||||
+ public static Collection<? extends Entity> getOptionalEntitiesCachedPositionedAs(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||
+ if (!(context.getSource().source instanceof net.minecraft.server.MinecraftServer)) return getOptionalEntities(context, name);
|
||||
+ EntitySelector selector = context.getArgument(name, EntitySelector.class);
|
||||
+ List<com.mojang.brigadier.context.ParsedCommandNode<CommandSourceStack>> nodes = context.getNodes();
|
||||
+ int idxStart = nodes.get(1).getRange().getStart();
|
||||
+ int idxEnd = nodes.get(3).getRange().getEnd();
|
||||
+ String selectorString = context.getInput().substring(idxStart, idxEnd);
|
||||
+ Collection<? extends Entity> entities = TICK_ENTITY_CACHE.get(selectorString);
|
||||
+ if (entities == null) {
|
||||
+ entities = selector.findEntities(context.getSource());
|
||||
+ TICK_ENTITY_CACHE.put(selectorString, entities);
|
||||
+ }
|
||||
+ return entities;
|
||||
+ }
|
||||
+ // Leaf end - Cache function getEntity calls
|
||||
public static Collection<? extends Entity> getOptionalEntities(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||
return context.getArgument(name, EntitySelector.class).findEntities(context.getSource());
|
||||
}
|
||||
diff --git a/net/minecraft/server/ServerFunctionManager.java b/net/minecraft/server/ServerFunctionManager.java
|
||||
index 10c79570432491bfb2bbfedf0491ab2b803d0c71..a8e64068c6ac76fe0c5bdebadd537f9f8a3435b9 100644
|
||||
--- a/net/minecraft/server/ServerFunctionManager.java
|
||||
+++ b/net/minecraft/server/ServerFunctionManager.java
|
||||
@@ -35,6 +35,7 @@ public class ServerFunctionManager {
|
||||
return this.server.getCommands().getDispatcher();
|
||||
}
|
||||
|
||||
+ int ticksCached = 0; // Leaf - Cache function getEntity calls
|
||||
public void tick() {
|
||||
if (this.server.tickRateManager().runsNormally()) {
|
||||
if (this.postReload) {
|
||||
@@ -44,6 +45,15 @@ public class ServerFunctionManager {
|
||||
}
|
||||
|
||||
this.executeTagFunctions(this.ticking, TICK_FUNCTION_TAG);
|
||||
+ // Leaf start - Cache function getEntity calls
|
||||
+ if (org.dreeam.leaf.config.modules.opt.CacheExecuteCommandResult.cacheExecuteCommandResult) {
|
||||
+ ticksCached++;
|
||||
+ if (ticksCached > 1) {
|
||||
+ net.minecraft.commands.arguments.EntityArgument.TICK_ENTITY_CACHE.clear();
|
||||
+ ticksCached = 0;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Cache function getEntity calls
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/server/commands/ExecuteCommand.java b/net/minecraft/server/commands/ExecuteCommand.java
|
||||
index 862ab68b3904873b72928463c6651aafe69c977c..512476098a6c03132e55ecc2c4c1cbcf2d644671 100644
|
||||
--- a/net/minecraft/server/commands/ExecuteCommand.java
|
||||
+++ b/net/minecraft/server/commands/ExecuteCommand.java
|
||||
@@ -148,7 +148,7 @@ public class ExecuteCommand {
|
||||
.then(Commands.literal("as").then(Commands.argument("targets", EntityArgument.entities()).fork(literalCommandNode, commandContext -> {
|
||||
List<CommandSourceStack> list = Lists.newArrayList();
|
||||
|
||||
- for (Entity entity : EntityArgument.getOptionalEntities(commandContext, "targets")) {
|
||||
+ for (Entity entity : org.dreeam.leaf.config.modules.opt.CacheExecuteCommandResult.cacheExecuteCommandResult ? EntityArgument.getOptionalEntitiesCachedAs(commandContext, "targets") : EntityArgument.getOptionalEntities(commandContext, "targets")) { // Leaf - Cache function getEntity calls
|
||||
list.add(commandContext.getSource().withEntity(entity));
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class ExecuteCommand {
|
||||
.then(Commands.literal("as").then(Commands.argument("targets", EntityArgument.entities()).fork(literalCommandNode, context -> {
|
||||
List<CommandSourceStack> list = Lists.newArrayList();
|
||||
|
||||
- for (Entity entity : EntityArgument.getOptionalEntities(context, "targets")) {
|
||||
+ for (Entity entity : org.dreeam.leaf.config.modules.opt.CacheExecuteCommandResult.cacheExecuteCommandResult ? EntityArgument.getOptionalEntitiesCachedPositionedAs(context, "targets") : EntityArgument.getOptionalEntities(context, "targets")) { // Leaf - Cache function getEntity calls
|
||||
list.add(context.getSource().withPosition(entity.position()));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] optimize waypoint
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index bdac75d6c9805af0363d2d183330318ca2ff82da..2b29b0e5334ad9f8b3768e9b198565f093c6d3a4 100644
|
||||
index e054c2416919fe8814412e6e06cd82e4ea537c84..a253d714670f932d67e2c44fdf895716b6b595ec 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -5144,6 +5144,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -6,7 +6,7 @@ Subject: [PATCH] Fix Paper config fixClimbingBypassingCrammingRule
|
||||
Waiting for Paper#12793
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index 3a669d98db60bfe19aa0c4b55dc28d06d44f7b88..fdb6527c9d7e18c37e681ea2d8e4428ece49e2ff 100644
|
||||
index 5307e80f6e84df7a053e7132883d8338bbd751a0..d6be86981219f0fe0db15d36d9c85e9a56020373 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -3850,7 +3850,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -5,29 +5,12 @@ Subject: [PATCH] Skip inactive entity for execute
|
||||
|
||||
|
||||
diff --git a/net/minecraft/commands/arguments/EntityArgument.java b/net/minecraft/commands/arguments/EntityArgument.java
|
||||
index 4acf68e42a9644612608c8521020a989cbdea4a9..76487244de9caad06696f2f4910c52c09547f775 100644
|
||||
index 8f6a1788b5ca396b79a638955fc6a6b3a276337f..43939f516c0270252c8fe3723f95a0dd87061301 100644
|
||||
--- a/net/minecraft/commands/arguments/EntityArgument.java
|
||||
+++ b/net/minecraft/commands/arguments/EntityArgument.java
|
||||
@@ -76,7 +76,7 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
||||
String selectorString = context.getInput().substring(idxStart, idxEnd);
|
||||
Collection<? extends Entity> entities = TICK_ENTITY_CACHE.get(selectorString);
|
||||
if (entities == null) {
|
||||
- entities = selector.findEntities(context.getSource());
|
||||
+ entities = org.dreeam.leaf.config.modules.opt.SkipInactiveEntityForExecute.skipInactiveEntityForExecute ? selector.findEntitiesSkipInactive(context.getSource()) : selector.findEntities(context.getSource());
|
||||
TICK_ENTITY_CACHE.put(selectorString, entities);
|
||||
}
|
||||
return entities;
|
||||
@@ -90,14 +90,17 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
||||
String selectorString = context.getInput().substring(idxStart, idxEnd);
|
||||
Collection<? extends Entity> entities = TICK_ENTITY_CACHE.get(selectorString);
|
||||
if (entities == null) {
|
||||
- entities = selector.findEntities(context.getSource());
|
||||
+ entities = org.dreeam.leaf.config.modules.opt.SkipInactiveEntityForExecute.skipInactiveEntityForExecute ? selector.findEntitiesSkipInactive(context.getSource()) : selector.findEntities(context.getSource()); // Leaf - Skip inactive entity for execute
|
||||
TICK_ENTITY_CACHE.put(selectorString, entities);
|
||||
}
|
||||
return entities;
|
||||
@@ -66,7 +66,10 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
||||
}
|
||||
// Leaf end - Cache function getEntity calls
|
||||
|
||||
public static Collection<? extends Entity> getOptionalEntities(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||
- return context.getArgument(name, EntitySelector.class).findEntities(context.getSource());
|
||||
+ // Leaf start - Skip inactive entity for execute
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.dreeam.leaf.config.modules.opt;
|
||||
|
||||
import org.dreeam.leaf.config.ConfigModules;
|
||||
import org.dreeam.leaf.config.EnumConfigCategory;
|
||||
import org.dreeam.leaf.config.annotations.Experimental;
|
||||
|
||||
public class CacheExecuteCommandResult extends ConfigModules {
|
||||
|
||||
public String getBasePath() {
|
||||
return EnumConfigCategory.PERF.getBaseKeyName() + ".datapack";
|
||||
}
|
||||
|
||||
@Experimental
|
||||
public static boolean cacheExecuteCommandResult = false;
|
||||
|
||||
@Override
|
||||
public void onLoaded() {
|
||||
cacheExecuteCommandResult = config.getBoolean(getBasePath() + ".cache-execute-command-result", cacheExecuteCommandResult,
|
||||
config.pickStringRegionBased("""
|
||||
*** Experimental Feature ***
|
||||
Cache the result of same execute command in the current and next tick.
|
||||
Will improve performance on servers with massive datapack functions.""",
|
||||
"""
|
||||
*** 实验性功能 ***
|
||||
缓存当前和下一 tick 相同的 execute 命令结果.
|
||||
将会提升有大量数据包函数的服务器性能."""));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user