mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
69a4a30e47
A recent commit has been made that caused patches to be out of order, rebuilding
65 lines
3 KiB
Diff
65 lines
3 KiB
Diff
From 3c2d443821191fe49500c40d6c4634b59e5af892 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 8bc1e3b976..114f958601 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
|
|
|