Skip to content

Commit 7c2d2d6

Browse files
committed
Skip libraries
Major speedup
1 parent f5cc3e0 commit 7c2d2d6

File tree

3 files changed

+87
-65
lines changed

3 files changed

+87
-65
lines changed

Diff for: src/main/java/makamys/coretweaks/asm/ModDiscovererTransformer.java

+3-61
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.objectweb.asm.tree.MethodInsnNode;
1616
import org.objectweb.asm.tree.MethodNode;
1717

18+
import makamys.coretweaks.util.DefaultLibraries;
1819
import net.minecraft.launchwrapper.IClassTransformer;
1920

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

8283
public static boolean redirectKnownLibrariesContains(List<String> list, String obj, File file) {
8384
assert file.getName().equals(obj);
84-
return list.contains(obj) || isDefaultLibrary(file);
85-
}
86-
87-
/* From Forge 1.12.2-14.23.5.2847 */
88-
private static boolean isDefaultLibrary(File file)
89-
{
90-
String home = System.getProperty("java.home"); // Nullcheck just in case some JVM decides to be stupid
91-
if (home != null && file.getAbsolutePath().startsWith(home)) return true;
92-
// Should really pull this from the json somehow, but we dont have that at runtime.
93-
String name = file.getName();
94-
if (!name.endsWith(".jar")) return false;
95-
String[] prefixes =
96-
{
97-
"launchwrapper-",
98-
"asm-all-",
99-
"akka-actor_2.11-",
100-
"config-",
101-
"scala-",
102-
"jopt-simple-",
103-
"lzma-",
104-
"realms-",
105-
"httpclient-",
106-
"httpcore-",
107-
"vecmath-",
108-
"trove4j-",
109-
"icu4j-core-mojang-",
110-
"codecjorbis-",
111-
"codecwav-",
112-
"libraryjavawound-",
113-
"librarylwjglopenal-",
114-
"soundsystem-",
115-
"netty-all-",
116-
"guava-",
117-
"commons-lang3-",
118-
"commons-compress-",
119-
"commons-logging-",
120-
"commons-io-",
121-
"commons-codec-",
122-
"jinput-",
123-
"jutils-",
124-
"gson-",
125-
"authlib-",
126-
"log4j-api-",
127-
"log4j-core-",
128-
"lwjgl-",
129-
"lwjgl_util-",
130-
"twitch-",
131-
"jline-",
132-
"jna-",
133-
"platform-",
134-
"oshi-core-",
135-
"netty-",
136-
"libraryjavasound-",
137-
"fastutil-",
138-
"lombok-"
139-
};
140-
for (String s : prefixes)
141-
{
142-
if (name.startsWith(s)) return true;
143-
}
144-
return false;
85+
return list.contains(obj) || DefaultLibraries.isDefaultLibrary(file);
14586
}
87+
14688
}

Diff for: src/main/java/makamys/coretweaks/optimization/PrefixedClasspathResourceAccelerator.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.zip.ZipFile;
2121

2222
import lombok.SneakyThrows;
23+
import makamys.coretweaks.util.DefaultLibraries;
2324
import net.minecraft.client.resources.DefaultResourcePack;
2425
import net.minecraft.launchwrapper.Launch;
2526

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

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

37+
private boolean skipLibraries = true;
38+
3639
private List<Index> classSources;
3740

3841
private Map<String, List<Index>> directoryOwners = new HashMap<>();
@@ -41,10 +44,12 @@ private void init() {
4144
long t0 = System.nanoTime();
4245
classSources = new ArrayList<>();
4346
for(URL url : Launch.classLoader.getSources().stream().distinct().collect(Collectors.toList())) {
44-
try {
45-
classSources.add(Index.fromURL(url));
46-
} catch(Exception e) {
47-
LOGGER.warn("Failed to index file " + url, e);
47+
if(!skipLibraries || !DefaultLibraries.isDefaultLibrary(url)) {
48+
try {
49+
classSources.add(Index.fromURL(url));
50+
} catch(Exception e) {
51+
LOGGER.warn("Failed to index file " + url, e);
52+
}
4853
}
4954
}
5055
long t1 = System.nanoTime();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package makamys.coretweaks.util;
2+
3+
import java.io.File;
4+
import java.net.URISyntaxException;
5+
import java.net.URL;
6+
7+
public class DefaultLibraries {
8+
/* From Forge 1.12.2-14.23.5.2847 */
9+
public static boolean isDefaultLibrary(File file)
10+
{
11+
String home = System.getProperty("java.home"); // Nullcheck just in case some JVM decides to be stupid
12+
if (home != null && file.getAbsolutePath().startsWith(home)) return true;
13+
// Should really pull this from the json somehow, but we dont have that at runtime.
14+
String name = file.getName();
15+
if (!name.endsWith(".jar")) return false;
16+
String[] prefixes =
17+
{
18+
"launchwrapper-",
19+
"asm-all-",
20+
"akka-actor_2.11-",
21+
"config-",
22+
"scala-",
23+
"jopt-simple-",
24+
"lzma-",
25+
"realms-",
26+
"httpclient-",
27+
"httpcore-",
28+
"vecmath-",
29+
"trove4j-",
30+
"icu4j-core-mojang-",
31+
"codecjorbis-",
32+
"codecwav-",
33+
"libraryjavawound-",
34+
"librarylwjglopenal-",
35+
"soundsystem-",
36+
"netty-all-",
37+
"guava-",
38+
"commons-lang3-",
39+
"commons-compress-",
40+
"commons-logging-",
41+
"commons-io-",
42+
"commons-codec-",
43+
"jinput-",
44+
"jutils-",
45+
"gson-",
46+
"authlib-",
47+
"log4j-api-",
48+
"log4j-core-",
49+
"lwjgl-",
50+
"lwjgl_util-",
51+
"twitch-",
52+
"jline-",
53+
"jna-",
54+
"platform-",
55+
"oshi-core-",
56+
"netty-",
57+
"libraryjavasound-",
58+
"fastutil-",
59+
"lombok-"
60+
};
61+
for (String s : prefixes)
62+
{
63+
if (name.startsWith(s)) return true;
64+
}
65+
return false;
66+
}
67+
68+
public static boolean isDefaultLibrary(URL url) {
69+
try {
70+
return isDefaultLibrary(new File(url.toURI()));
71+
} catch(URISyntaxException e) {
72+
return false;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)