From fcd01e5c3ea02783c26900584b29839865403693 Mon Sep 17 00:00:00 2001 From: Player Date: Tue, 3 Sep 2024 04:23:15 -0400 Subject: [PATCH] Use less path normalization due to poor performance on Windows (#971) --- .../ClasspathModCandidateFinder.java | 3 ++- .../DirectoryModCandidateFinder.java | 4 +++- .../loader/impl/discovery/ModDiscoverer.java | 21 +++++++------------ .../impl/launch/knot/KnotClassDelegate.java | 5 ++++- .../impl/discovery/GetNonFabricModsTest.java | 5 +++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java index 55caa1b1c..c9177123e 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ClasspathModCandidateFinder.java @@ -54,7 +54,8 @@ public void findCandidates(ModCandidateConsumer out) { URL url = mods.nextElement(); try { - Path path = LoaderUtil.normalizeExistingPath(UrlUtil.getCodeSource(url, "fabric.mod.json")); + Path path = UrlUtil.getCodeSource(url, "fabric.mod.json"); + assert path.equals(LoaderUtil.normalizeExistingPath(path)); List paths = pathGroups.get(path); if (paths == null) { diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java index eefcd4989..72fd5e89e 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java @@ -25,6 +25,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.EnumSet; +import net.fabricmc.loader.impl.util.LoaderUtil; import net.fabricmc.loader.impl.util.log.Log; import net.fabricmc.loader.impl.util.log.LogCategory; @@ -33,7 +34,7 @@ public class DirectoryModCandidateFinder implements ModCandidateFinder { private final boolean requiresRemap; public DirectoryModCandidateFinder(Path path, boolean requiresRemap) { - this.path = path; + this.path = LoaderUtil.normalizePath(path); this.requiresRemap = requiresRemap; } @@ -42,6 +43,7 @@ public void findCandidates(ModCandidateConsumer out) { if (!Files.exists(path)) { try { Files.createDirectory(path); + return; } catch (IOException e) { throw new RuntimeException("Could not create directory " + path, e); } diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/ModDiscoverer.java b/src/main/java/net/fabricmc/loader/impl/discovery/ModDiscoverer.java index fd0cde959..261294ce2 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/ModDiscoverer.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/ModDiscoverer.java @@ -92,24 +92,17 @@ public List discoverMods(FabricLoaderImpl loader, Map> futures = new ArrayList<>(); ModCandidateConsumer taskSubmitter = (paths, requiresRemap) -> { - if (paths.size() == 1) { - Path path = LoaderUtil.normalizeExistingPath(paths.get(0)); + List pendingPaths = new ArrayList<>(paths.size()); - if (processedPaths.add(path)) { - futures.add(pool.submit(new ModScanTask(Collections.singletonList(path), requiresRemap))); - } - } else { - List normalizedPaths = new ArrayList<>(paths.size()); + for (Path path : paths) { + assert path.equals(LoaderUtil.normalizeExistingPath(path)); - for (Path path : paths) { - normalizedPaths.add(LoaderUtil.normalizeExistingPath(path)); - } - - if (!processedPaths.containsAll(normalizedPaths)) { - processedPaths.addAll(normalizedPaths); - futures.add(pool.submit(new ModScanTask(normalizedPaths, requiresRemap))); + if (processedPaths.add(path)) { + pendingPaths.add(path); } } + + futures.add(pool.submit(new ModScanTask(pendingPaths, requiresRemap))); }; for (ModCandidateFinder finder : candidateFinders) { diff --git a/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java index 3e5d301d5..3e7e75f1d 100644 --- a/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java +++ b/src/main/java/net/fabricmc/loader/impl/launch/knot/KnotClassDelegate.java @@ -512,7 +512,10 @@ private static boolean hasRegularCodeSource(URL url) { private static Path getCodeSource(URL url, String fileName) { try { - return LoaderUtil.normalizeExistingPath(UrlUtil.getCodeSource(url, fileName)); + Path ret = UrlUtil.getCodeSource(url, fileName); + assert ret.equals(LoaderUtil.normalizeExistingPath(ret)); // ret should already be normalized + + return ret; } catch (UrlConversionException e) { throw ExceptionUtil.wrap(e); } diff --git a/src/test/java/net/fabricmc/loader/impl/discovery/GetNonFabricModsTest.java b/src/test/java/net/fabricmc/loader/impl/discovery/GetNonFabricModsTest.java index 4c864003b..636440eaa 100644 --- a/src/test/java/net/fabricmc/loader/impl/discovery/GetNonFabricModsTest.java +++ b/src/test/java/net/fabricmc/loader/impl/discovery/GetNonFabricModsTest.java @@ -38,6 +38,7 @@ import net.fabricmc.loader.impl.game.GameProvider; import net.fabricmc.loader.impl.launch.FabricLauncher; import net.fabricmc.loader.impl.launch.FabricLauncherBase; +import net.fabricmc.loader.impl.util.LoaderUtil; public class GetNonFabricModsTest { private FabricLoaderImpl loader; @@ -102,8 +103,8 @@ public void testGetNonFabricMods() throws ModResolutionException { public static class MockCandidateFinder implements ModCandidateFinder { @Override public void findCandidates(ModCandidateConsumer out) { - out.accept(Paths.get("./src/test/resources/testing/discovery/dummyFabricMod.jar"), false); - out.accept(Paths.get("./src/test/resources/testing/discovery/dummyNonFabricMod.jar"), false); + out.accept(LoaderUtil.normalizePath(Paths.get("src/test/resources/testing/discovery/dummyFabricMod.jar")), false); + out.accept(LoaderUtil.normalizePath(Paths.get("src/test/resources/testing/discovery/dummyNonFabricMod.jar")), false); } } }