Skip to content

Commit a8abed1

Browse files
committed
Merge 1.20 into 1.21.1
2 parents 07592fb + 8133198 commit a8abed1

File tree

11 files changed

+142
-21
lines changed

11 files changed

+142
-21
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/devenv/NarratorMixin.java

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.embeddedt.modernfix.common.mixin.feature.suppress_narrator_stacktrace;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import com.mojang.text2speech.Narrator;
6+
import com.mojang.text2speech.NarratorLinux;
7+
import com.mojang.text2speech.OperatingSystem;
8+
import net.minecraft.client.GameNarrator;
9+
import org.embeddedt.modernfix.ModernFix;
10+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
14+
@ClientOnlyMixin
15+
@Mixin(GameNarrator.class)
16+
public class GameNarratorMixin {
17+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/text2speech/Narrator;getNarrator()Lcom/mojang/text2speech/Narrator;"))
18+
private Narrator suppressStacktracePrinting(Operation<Narrator> original) {
19+
try {
20+
return switch (OperatingSystem.get()) {
21+
case LINUX -> new NarratorLinux();
22+
default -> original.call();
23+
};
24+
} catch (Narrator.InitializeException e) {
25+
ModernFix.LOGGER.warn("Failed to initialize Linux Narrator. Make sure you have libflite installed!");
26+
return Narrator.EMPTY;
27+
}
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.compact_mojang_registries;
2+
3+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
5+
import net.minecraft.core.HolderLookup;
6+
import net.minecraft.data.registries.VanillaRegistries;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
9+
@Mixin(VanillaRegistries.class)
10+
public class VanillaRegistriesMixin {
11+
private static HolderLookup.Provider STATIC_PROVIDER;
12+
13+
@WrapMethod(method = "createLookup")
14+
private static HolderLookup.Provider modernfix$memoizeLookup(Operation<HolderLookup.Provider> original) {
15+
synchronized (VanillaRegistries.class) {
16+
if (STATIC_PROVIDER == null) {
17+
STATIC_PROVIDER = original.call();
18+
}
19+
return STATIC_PROVIDER;
20+
}
21+
}
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.worldgen_allocation;
2+
3+
import net.minecraft.world.level.levelgen.SurfaceRules;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
6+
@Mixin(targets = {
7+
"net/minecraft/world/level/levelgen/SurfaceRules$BiomeConditionSource$1BiomeCondition",
8+
"net/minecraft/world/level/levelgen/SurfaceRules$StoneDepthCheck$1StoneDepthCondition",
9+
"net/minecraft/world/level/levelgen/SurfaceRules$VerticalGradientConditionSource$1VerticalGradientCondition",
10+
"net/minecraft/world/level/levelgen/SurfaceRules$WaterConditionSource$1WaterCondition",
11+
"net/minecraft/world/level/levelgen/SurfaceRules$YConditionSource$1YCondition",
12+
})
13+
public abstract class SurfaceRulesMixin extends SurfaceRules.LazyCondition {
14+
protected SurfaceRulesMixin(SurfaceRules.Context context) {
15+
super(context);
16+
}
17+
18+
/**
19+
* @author VoidsongDragonfly
20+
* @reason Replacing Vanilla's use of {@link SurfaceRules.LazyYCondition LazyYCondition} that causes performance
21+
* detriments due to unused caching behavior. The `lastUpdateY` field is updated every time the block position
22+
* changes (making the cache useful only within a single block), and the targeted condition objects are not interned
23+
* (meaning there is no caching happening anyway, as each instance uses its own cache).
24+
*
25+
*/
26+
@Override
27+
public boolean test() {
28+
return compute();
29+
}
30+
}

common/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,23 @@ public void run() {
8787
t.setDaemon(true);
8888
t.start();
8989
}
90+
91+
if (ModernFixPlatformHooks.INSTANCE.isClient() && ModernFixMixinPlugin.instance.isOptionEnabled("perf.thread_priorities.AdjustThreadCount")) {
92+
computeBetterThreadCount();
93+
}
94+
}
95+
}
96+
97+
private void computeBetterThreadCount() {
98+
// Allow user-provided thread count to take precedence
99+
if (System.getProperty("max.bg.threads") != null) {
100+
return;
90101
}
102+
// Server thread + client thread + GC thread
103+
int reservedCores = 3;
104+
int availableBackgroundCores = Math.max(1, Runtime.getRuntime().availableProcessors() - reservedCores);
105+
logger.info("Configuring Minecraft's max.bg.threads option with {} threads", availableBackgroundCores);
106+
System.setProperty("max.bg.threads", String.valueOf(availableBackgroundCores));
91107
}
92108

93109

common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.*;
66
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
77
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
8+
import org.apache.commons.lang3.SystemUtils;
89
import org.apache.logging.log4j.LogManager;
910
import org.apache.logging.log4j.Logger;
1011
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
@@ -21,6 +22,9 @@
2122
import java.io.*;
2223
import java.net.URL;
2324
import java.nio.charset.StandardCharsets;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
import java.nio.file.Paths;
2428
import java.util.*;
2529
import java.util.function.BooleanSupplier;
2630
import java.util.regex.Pattern;
@@ -164,7 +168,6 @@ public DefaultSettingMapBuilder put(String key, Boolean value) {
164168
.put("mixin.feature.direct_stack_trace", false)
165169
.put("mixin.feature.stalled_chunk_load_detection", false)
166170
.put("mixin.bugfix.restore_old_dragon_movement", false)
167-
.put("mixin.perf.worldgen_allocation", false) // experimental
168171
.put("mixin.feature.cause_lag_by_disabling_threads", false)
169172
.put("mixin.bugfix.missing_block_entities", false)
170173
.put("mixin.feature.blockentity_incorrect_thread", false)
@@ -310,6 +313,32 @@ private void readJVMProperties() {
310313
}
311314
}
312315

316+
private void readGlobalProperties() {
317+
Path minecraftFolder;
318+
if (SystemUtils.IS_OS_MAC) {
319+
minecraftFolder = Paths.get(System.getProperty("user.home"), "Library", "Application Support", "minecraft");
320+
} else if (SystemUtils.IS_OS_WINDOWS) {
321+
minecraftFolder = Paths.get(System.getenv("APPDATA"), ".minecraft");
322+
} else {
323+
minecraftFolder = Paths.get(System.getProperty("user.home"), ".minecraft");
324+
}
325+
Path globalPropsFile = minecraftFolder.resolve("global").resolve("modernfix-global-mixins.properties");
326+
try {
327+
if (Files.exists(globalPropsFile)) {
328+
Properties properties = new Properties();
329+
try (var is = Files.newInputStream(globalPropsFile)) {
330+
properties.load(is);
331+
}
332+
if (!properties.isEmpty()) {
333+
LOGGER.info("Global properties specified: [{}]", properties.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(", ")));
334+
readProperties(properties);
335+
}
336+
}
337+
} catch (Exception e) {
338+
LOGGER.error("Error reading global properties file", e);
339+
}
340+
}
341+
313342
private void readProperties(Properties props) {
314343
if(ALLOW_OVERRIDE_OVERRIDES)
315344
LOGGER.fatal("JVM argument given to override mod overrides. Issues opened with this option present will be ignored unless they can be reproduced without.");
@@ -399,6 +428,7 @@ public static ModernFixEarlyConfig load(File file) {
399428
LOGGER.warn("Could not write configuration file", e);
400429
}
401430

431+
config.readGlobalProperties();
402432
config.readJVMProperties();
403433
}
404434

common/src/main/java/org/embeddedt/modernfix/spark/SparkLaunchProfiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SparkLaunchProfiler {
3333
private static PlatformInfo platformInfo = new ModernFixPlatformInfo();
3434
private static CommandSender commandSender = new ModernFixCommandSender();
3535
private static Map<String, Sampler> ongoingSamplers = new Object2ReferenceOpenHashMap<>();
36-
private static ExecutorService executor = Executors.newSingleThreadScheduledExecutor((new ThreadFactoryBuilder()).setNameFormat("spark-modernfix-async-worker").build());
36+
private static ExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("spark-modernfix-async-worker").build());
3737
private static final SparkPlatform platform = new SparkPlatform(new ModernFixSparkPlugin());
3838

3939
private static final boolean USE_JAVA_SAMPLER_FOR_LAUNCH = !Boolean.getBoolean("modernfix.profileWithAsyncSampler");

common/src/main/resources/assets/modernfix/lang/de_de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,6 @@
120120
"modernfix.option.mixin.perf.compact_mojang_registries": "(Fabric) Experimentelle Option, die die Speichernutzung von Registern um etwa 50 % reduziert. In den meisten Modpacks nicht nützlich, es sei denn, sie enthalten Millionen von Blöcken und Gegenständen.",
121121
"modernfix.option.mixin.perf.dynamic_block_codecs": "Vermeidet das Speichern eines Codecs für jeden Block (Zustand) und generiert und speichert ihn stattdessen bei Bedarf im laufenden Betrieb. Im Allgemeinen lohnt es sich nicht, es zu aktivieren, es sei denn, Sie haben eine Million Blöcke/Elemente.",
122122
"modernfix.option.mixin.perf.faster_command_suggestions": "Verringern Sie Verzögerungen, wenn beim Eingeben eines Befehls Hunderttausende Vorschläge eingehen",
123-
"modernfix.option.mixin.perf.mojang_registry_size": "Behebt ein Problem, das dazu führt, dass sich die Registrierung von Blöcken/Elementen proportional zur bereits registrierten Anzahl verlangsamt. Dies verbessert die Startzeit."
123+
"modernfix.option.mixin.perf.mojang_registry_size": "Behebt ein Problem, das dazu führt, dass sich die Registrierung von Blöcken/Elementen proportional zur bereits registrierten Anzahl verlangsamt. Dies verbessert die Startzeit.",
124+
"modernfix.option.mixin.feature.suppress_narrator_stacktrace": "Hält das Spiel davon ab, einen sehr langen Stacktrace zu loggen, wenn der Erzähler auf Linux nicht erfolgreich lädt (oft verursacht dadurch, dass libflite nicht installiert ist)."
124125
}

common/src/main/resources/assets/modernfix/lang/en_us.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@
152152
"modernfix.option.mixin.perf.memoize_creative_tab_build": "Improves on vanilla's existing caching for creative tab contents in a way that is compatible with the timing requirements of mods like JEI/EMI. This can reduce the lag spike when opening the creative inventory for the first time in a modpack.",
153153
"modernfix.option.mixin.perf.potential_spawns_alloc": "Optimizes the Forge event for finding potential mobs that can spawn. This reduces allocations and the overhead of rebuilding a weighted list when no mods modify the potential spawns.",
154154
"modernfix.option.mixin.perf.ticking_chunk_alloc": "Optimizes chunk ticking in vanilla to reduce allocations.",
155-
"modernfix.option.mixin.perf.worldgen_allocation": "Optimizes some world generation logic in vanilla to reduce object allocations."
155+
"modernfix.option.mixin.perf.worldgen_allocation": "Optimizes some world generation logic in vanilla to reduce object allocations.",
156+
"modernfix.option.mixin.feature.suppress_narrator_stacktrace": "Prevents the game from logging a very long stacktrace when the narrator fails to load on Linux (usually caused by not having libflite installed)."
156157
}

common/src/main/resources/modernfix.accesswidener

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ accessible field net/minecraft/world/level/Level blockEntityTickers Ljava/util/L
1111
accessible class net/minecraft/client/renderer/RenderType$CompositeRenderType
1212
accessible method net/minecraft/nbt/CompoundTag <init> (Ljava/util/Map;)V
1313

14+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$Condition
15+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition
1416
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRule
1517
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SurfaceRule
18+
accessible class net/minecraft/world/level/levelgen/SurfaceRules$Context
1619
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker
1720
accessible class net/minecraft/world/level/levelgen/DensityFunctions$Marker$Type
1821
accessible method net/minecraft/world/level/levelgen/DensityFunctions$Marker <init> (Lnet/minecraft/world/level/levelgen/DensityFunctions$Marker$Type;Lnet/minecraft/world/level/levelgen/DensityFunction;)V

0 commit comments

Comments
 (0)