Replace ThreadLocal with ConcurrentHashMap in CommandSourceStack (#6325)
This object is created so often that it likely creates problems with the ThreadLocalMap because the weak references can't be cleaned up fast enough. This has manifest as lag seemingly caused by WorldEdit: https://github.com/EngineHub/WorldEdit/issues/1668
This commit is contained in:
parent
889718222e
commit
1291aa829a
1 changed files with 15 additions and 4 deletions
|
@ -17,11 +17,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
if (source instanceof CommandSourceStack) {
|
if (source instanceof CommandSourceStack) {
|
||||||
try {
|
try {
|
||||||
- ((CommandSourceStack) source).currentCommand = this;
|
- ((CommandSourceStack) source).currentCommand = this;
|
||||||
+ ((CommandSourceStack) source).currentCommand.set(this); // Paper
|
+ ((CommandSourceStack) source).currentCommand.put(Thread.currentThread(), this); // Paper
|
||||||
return this.requirement.test(source);
|
return this.requirement.test(source);
|
||||||
} finally {
|
} finally {
|
||||||
- ((CommandSourceStack) source).currentCommand = null;
|
- ((CommandSourceStack) source).currentCommand = null;
|
||||||
+ ((CommandSourceStack) source).currentCommand.set(null); // Paper
|
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
@ -29,12 +29,23 @@ diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
||||||
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
||||||
|
@@ -0,0 +0,0 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
+import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
+import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.BinaryOperator;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
@@ -0,0 +0,0 @@ public class CommandSourceStack implements SharedSuggestionProvider, com.destroy
|
@@ -0,0 +0,0 @@ public class CommandSourceStack implements SharedSuggestionProvider, com.destroy
|
||||||
private final ResultConsumer<CommandSourceStack> consumer;
|
private final ResultConsumer<CommandSourceStack> consumer;
|
||||||
private final EntityAnchorArgument.Anchor anchor;
|
private final EntityAnchorArgument.Anchor anchor;
|
||||||
private final Vec2 rotation;
|
private final Vec2 rotation;
|
||||||
- public volatile CommandNode currentCommand; // CraftBukkit
|
- public volatile CommandNode currentCommand; // CraftBukkit
|
||||||
+ public ThreadLocal<CommandNode> currentCommand = new ThreadLocal<>(); // CraftBukkit // Paper
|
+ public Map<Thread, CommandNode> currentCommand = new ConcurrentHashMap<>(); // CraftBukkit // Paper
|
||||||
|
|
||||||
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
||||||
this(output, pos, rot, world, level, name, displayName, server, entity, false, (commandcontext, flag, j) -> {
|
this(output, pos, rot, world, level, name, displayName, server, entity, false, (commandcontext, flag, j) -> {
|
||||||
|
@ -44,7 +55,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
- CommandNode currentCommand = this.currentCommand;
|
- CommandNode currentCommand = this.currentCommand;
|
||||||
+ // Paper start - fix concurrency issue
|
+ // Paper start - fix concurrency issue
|
||||||
+ CommandNode currentCommand = this.currentCommand.get();
|
+ CommandNode currentCommand = this.currentCommand.get(Thread.currentThread());
|
||||||
if (currentCommand != null) {
|
if (currentCommand != null) {
|
||||||
return this.hasPermission(level, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
|
return this.hasPermission(level, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue