Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0392-Optimize-DataFixer-Bootstrap-to-prebuild-faster.patch
Caleb Bassham 64840b3018 Fix NPE when setting a player's spectator target (#1596)
Fix NPE when setting a player's spectator target
2018-10-21 20:27:53 +01:00

66 Zeilen
3.0 KiB
Diff

From 91eccecb6628c012672846b4faeef2ee5f41cd45 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 12 Oct 2018 01:28:32 -0400
Subject: [PATCH] Optimize DataFixer Bootstrap to prebuild faster
diff --git a/src/main/java/com/mojang/datafixers/DataFixerBuilder.java b/src/main/java/com/mojang/datafixers/DataFixerBuilder.java
index 8bc1e3b9..114f9586 100644
--- a/src/main/java/com/mojang/datafixers/DataFixerBuilder.java
+++ b/src/main/java/com/mojang/datafixers/DataFixerBuilder.java
@@ -12,7 +12,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.Executor;
import java.util.function.BiFunction;
@@ -60,16 +62,37 @@ public class DataFixerBuilder {
final DataFixerUpper fixerUpper = new DataFixerUpper(new Int2ObjectAVLTreeMap<>(schemas), new ArrayList<>(globalList), new IntAVLTreeSet(fixerVersions));
executor.execute(() -> {
- final IntBidirectionalIterator iterator = fixerUpper.fixerVersions().iterator();
+ List<Runnable> taskList = new ArrayList<>();
+ IntBidirectionalIterator iterator = fixerUpper.fixerVersions().iterator();
while (iterator.hasNext()) {
final int versionKey = iterator.nextInt();
final Schema schema = schemas.get(versionKey);
+
for (final String typeName: schema.types()) {
- final Type<?> dataType = schema.getType(() -> typeName);
- final TypeRewriteRule rule = fixerUpper.getRule(DataFixUtils.getVersion(versionKey), dataVersion);
- dataType.rewrite(rule, DataFixerUpper.OPTIMIZATION_RULE);
+ taskList.add(() -> {
+ final Type<?> dataType = schema.getType(() -> typeName);
+ final TypeRewriteRule rule = fixerUpper.getRule(DataFixUtils.getVersion(versionKey), dataVersion);
+ dataType.rewrite(rule, DataFixerUpper.OPTIMIZATION_RULE);
+ });
}
}
+
+ // Divide up into sets of tasks by number of CPU cores
+ // Some tasks are faster than others, randomize it to try to divide it more
+ Collections.shuffle(taskList);
+ List<List<Runnable>> buildQueue = new ArrayList<>();
+ List<Runnable> current = new ArrayList<>();
+ buildQueue.add(current);
+ int maxTasks = (int) Math.max(1, Math.floor(taskList.size() / (float)Math.min(6, Runtime.getRuntime().availableProcessors()-2)));
+ for (Runnable task : taskList) {
+ if (current.size() > maxTasks) {
+ current = new ArrayList<>();
+ buildQueue.add(current);
+ }
+ current.add(task);
+ }
+
+ buildQueue.forEach(queue -> executor.execute(() -> queue.forEach(Runnable::run)));
});
return fixerUpper;
--
2.19.1