Skip to content

Commit

Permalink
Skip libraries
Browse files Browse the repository at this point in the history
Major speedup
  • Loading branch information
makamys committed Dec 18, 2023
1 parent f5cc3e0 commit 7c2d2d6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 65 deletions.
64 changes: 3 additions & 61 deletions src/main/java/makamys/coretweaks/asm/ModDiscovererTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

import makamys.coretweaks.util.DefaultLibraries;
import net.minecraft.launchwrapper.IClassTransformer;

public class ModDiscovererTransformer implements IClassTransformer {
Expand Down Expand Up @@ -81,66 +82,7 @@ private static byte[] doTransform(byte[] bytes) {

public static boolean redirectKnownLibrariesContains(List<String> list, String obj, File file) {
assert file.getName().equals(obj);
return list.contains(obj) || isDefaultLibrary(file);
}

/* From Forge 1.12.2-14.23.5.2847 */
private static boolean isDefaultLibrary(File file)
{
String home = System.getProperty("java.home"); // Nullcheck just in case some JVM decides to be stupid
if (home != null && file.getAbsolutePath().startsWith(home)) return true;
// Should really pull this from the json somehow, but we dont have that at runtime.
String name = file.getName();
if (!name.endsWith(".jar")) return false;
String[] prefixes =
{
"launchwrapper-",
"asm-all-",
"akka-actor_2.11-",
"config-",
"scala-",
"jopt-simple-",
"lzma-",
"realms-",
"httpclient-",
"httpcore-",
"vecmath-",
"trove4j-",
"icu4j-core-mojang-",
"codecjorbis-",
"codecwav-",
"libraryjavawound-",
"librarylwjglopenal-",
"soundsystem-",
"netty-all-",
"guava-",
"commons-lang3-",
"commons-compress-",
"commons-logging-",
"commons-io-",
"commons-codec-",
"jinput-",
"jutils-",
"gson-",
"authlib-",
"log4j-api-",
"log4j-core-",
"lwjgl-",
"lwjgl_util-",
"twitch-",
"jline-",
"jna-",
"platform-",
"oshi-core-",
"netty-",
"libraryjavasound-",
"fastutil-",
"lombok-"
};
for (String s : prefixes)
{
if (name.startsWith(s)) return true;
}
return false;
return list.contains(obj) || DefaultLibraries.isDefaultLibrary(file);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.zip.ZipFile;

import lombok.SneakyThrows;
import makamys.coretweaks.util.DefaultLibraries;
import net.minecraft.client.resources.DefaultResourcePack;
import net.minecraft.launchwrapper.Launch;

Expand All @@ -33,6 +34,8 @@ public class PrefixedClasspathResourceAccelerator {

private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("coretweaks.debugPrefixedClasspathResourceAccelerator", "false"));

private boolean skipLibraries = true;

private List<Index> classSources;

private Map<String, List<Index>> directoryOwners = new HashMap<>();
Expand All @@ -41,10 +44,12 @@ private void init() {
long t0 = System.nanoTime();
classSources = new ArrayList<>();
for(URL url : Launch.classLoader.getSources().stream().distinct().collect(Collectors.toList())) {
try {
classSources.add(Index.fromURL(url));
} catch(Exception e) {
LOGGER.warn("Failed to index file " + url, e);
if(!skipLibraries || !DefaultLibraries.isDefaultLibrary(url)) {
try {
classSources.add(Index.fromURL(url));
} catch(Exception e) {
LOGGER.warn("Failed to index file " + url, e);
}
}
}
long t1 = System.nanoTime();
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/makamys/coretweaks/util/DefaultLibraries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package makamys.coretweaks.util;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

public class DefaultLibraries {
/* From Forge 1.12.2-14.23.5.2847 */
public static boolean isDefaultLibrary(File file)
{
String home = System.getProperty("java.home"); // Nullcheck just in case some JVM decides to be stupid
if (home != null && file.getAbsolutePath().startsWith(home)) return true;
// Should really pull this from the json somehow, but we dont have that at runtime.
String name = file.getName();
if (!name.endsWith(".jar")) return false;
String[] prefixes =
{
"launchwrapper-",
"asm-all-",
"akka-actor_2.11-",
"config-",
"scala-",
"jopt-simple-",
"lzma-",
"realms-",
"httpclient-",
"httpcore-",
"vecmath-",
"trove4j-",
"icu4j-core-mojang-",
"codecjorbis-",
"codecwav-",
"libraryjavawound-",
"librarylwjglopenal-",
"soundsystem-",
"netty-all-",
"guava-",
"commons-lang3-",
"commons-compress-",
"commons-logging-",
"commons-io-",
"commons-codec-",
"jinput-",
"jutils-",
"gson-",
"authlib-",
"log4j-api-",
"log4j-core-",
"lwjgl-",
"lwjgl_util-",
"twitch-",
"jline-",
"jna-",
"platform-",
"oshi-core-",
"netty-",
"libraryjavasound-",
"fastutil-",
"lombok-"
};
for (String s : prefixes)
{
if (name.startsWith(s)) return true;
}
return false;
}

public static boolean isDefaultLibrary(URL url) {
try {
return isDefaultLibrary(new File(url.toURI()));
} catch(URISyntaxException e) {
return false;
}
}
}

0 comments on commit 7c2d2d6

Please sign in to comment.