Skip to content

Commit 16551be

Browse files
committed
Updated Gradle to 8.10, added ResourceLocation string deduplication (from CaffeineMC/hydrogen-fabric)
Signed-off-by: xtrm <[email protected]>
1 parent 2240867 commit 16551be

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ This list may not always be up-to-date. To view an updated list, click [here](ht
355355
<details>
356356
<summary>License disclaimers</summary>
357357

358-
This work, "PolyPatcher", uses code from CaffeineMC's "lithium-fabric", licensed under the LGPL-3.0 license. The original license is included in the repository.
359-
https://github.com/CaffeineMC/lithium-fabric/tree/develop
360-
https://github.com/CaffeineMC/lithium-fabric/blob/develop/LICENSE.txt
358+
PolyPatcher uses code from [CaffeineMC's lithium mod](https://github.com/CaffeineMC/lithium-fabric/tree/develop), licensed under the [LGPL-3.0 license](https://github.com/CaffeineMC/lithium-fabric/blob/develop/LICENSE.txt).
359+
360+
PolyPatcher uses code from [CaffeineMC's hydrogen mod](https://github.com/CaffeineMC/hydrogen-fabric/tree/develop), licensed under the [LGPL-3.0 license](https://github.com/CaffeineMC/hydrogen-fabric/blob/1.17.x/LICENSE.txt).
361361

362362
</details>

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package club.sk1er.patcher.mixins.performance;
2+
3+
import me.jellysquid.mods.hydrogen.common.dedup.IdentifierCaches;
4+
import net.minecraft.util.ResourceLocation;
5+
import org.spongepowered.asm.mixin.Final;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Mutable;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
/**
14+
* From <a href="https://github.com/CaffeineMC/hydrogen-fabric/blob/95da36046c2f55617a76ebb8ea1e1f2a330330e5/src/main/java/me/jellysquid/mods/hydrogen/mixin/util/MixinIdentifier.java">CaffeineMC/hydrogen-fabric</a> under GNU LGPL v3.0
15+
*/
16+
@Mixin(ResourceLocation.class)
17+
public class ResourceLocation_Deduplicate {
18+
@Shadow
19+
@Final
20+
@Mutable
21+
protected String resourceDomain;
22+
23+
@Shadow
24+
@Final
25+
@Mutable
26+
protected String resourcePath;
27+
28+
@Inject(method = "<init>(I[Ljava/lang/String;)V", at = @At("RETURN"))
29+
private void reinit(int what, String[] id, CallbackInfo ci) {
30+
this.resourceDomain = IdentifierCaches.NAMESPACES.deduplicate(this.resourceDomain);
31+
this.resourcePath = IdentifierCaches.PATH.deduplicate(this.resourcePath);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package me.jellysquid.mods.hydrogen.common.dedup;
2+
3+
import it.unimi.dsi.fastutil.Hash;
4+
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
5+
6+
import java.util.Objects;
7+
8+
public class DeduplicationCache<T> {
9+
private final ObjectOpenCustomHashSet<T> pool;
10+
11+
private int attemptedInsertions = 0;
12+
private int deduplicated = 0;
13+
14+
public DeduplicationCache(Hash.Strategy<T> strategy) {
15+
this.pool = new ObjectOpenCustomHashSet<>(strategy);
16+
}
17+
18+
public DeduplicationCache() {
19+
this.pool = new ObjectOpenCustomHashSet<>(new Hash.Strategy<T>() {
20+
@Override
21+
public int hashCode(T o) {
22+
return Objects.hashCode(o);
23+
}
24+
25+
@Override
26+
public boolean equals(T a, T b) {
27+
return Objects.equals(a, b);
28+
}
29+
});
30+
}
31+
32+
public synchronized T deduplicate(T item) {
33+
this.attemptedInsertions++;
34+
35+
T result = this.pool.addOrGet(item);
36+
37+
if (result != item) {
38+
this.deduplicated++;
39+
}
40+
41+
return result;
42+
}
43+
44+
public synchronized void clearCache() {
45+
this.attemptedInsertions = 0;
46+
this.deduplicated = 0;
47+
48+
this.pool.clear();
49+
}
50+
51+
@Override
52+
public synchronized String toString() {
53+
return String.format("DeduplicationCache ( %d/%d de-duplicated, %d pooled )",
54+
this.deduplicated, this.attemptedInsertions, this.pool.size());
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package me.jellysquid.mods.hydrogen.common.dedup;
2+
3+
public class IdentifierCaches {
4+
public static final DeduplicationCache<String> NAMESPACES = new DeduplicationCache<>();
5+
public static final DeduplicationCache<String> PATH = new DeduplicationCache<>();
6+
}

src/main/resources/mixins.patcher.json

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
"performance.RenderChunkMixin_OptimizeSpecialTileEntities",
250250
"performance.RenderEntityItemMixin_EntityCulling",
251251
"performance.RenderGlobalMixin_LimitVisGraphScan",
252+
"performance.ResourceLocation_Deduplicate",
252253
"performance.ResourcePackRepositoryMixin_FasterSearching",
253254
"performance.SimpleReloadableResourceManager_OnlyRefreshNecessaryListeners",
254255
"performance.TexturedQuadMixin_BatchDraw",

0 commit comments

Comments
 (0)