Skip to content

Commit

Permalink
Use less path normalization due to poor performance on Windows (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfPlayer1 committed Sep 3, 2024
1 parent 4ffece2 commit fcd01e5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> paths = pathGroups.get(path);

if (paths == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,17 @@ public List<ModCandidateImpl> discoverMods(FabricLoaderImpl loader, Map<String,
List<Future<ModCandidateImpl>> futures = new ArrayList<>();

ModCandidateConsumer taskSubmitter = (paths, requiresRemap) -> {
if (paths.size() == 1) {
Path path = LoaderUtil.normalizeExistingPath(paths.get(0));
List<Path> pendingPaths = new ArrayList<>(paths.size());

if (processedPaths.add(path)) {
futures.add(pool.submit(new ModScanTask(Collections.singletonList(path), requiresRemap)));
}
} else {
List<Path> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit fcd01e5

Please sign in to comment.