66 lines
3.0 KiB
Diff
66 lines
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
|
|
|