Skip to content

Commit

Permalink
Updated Gradle to 8.10, added ResourceLocation string deduplication (…
Browse files Browse the repository at this point in the history
…from CaffeineMC/hydrogen-fabric)

Signed-off-by: xtrm <[email protected]>
  • Loading branch information
xtrm-en committed Aug 30, 2024
1 parent 2240867 commit eb19b29
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ This list may not always be up-to-date. To view an updated list, click [here](ht
<details>
<summary>License disclaimers</summary>

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.
https://github.com/CaffeineMC/lithium-fabric/tree/develop
https://github.com/CaffeineMC/lithium-fabric/blob/develop/LICENSE.txt
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).

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).

</details>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package club.sk1er.patcher.mixins.performance;

import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* 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
*/
@Mixin(ResourceLocation.class)
public class ResourceLocation_Deduplicate {
@Shadow
@Final
@Mutable
protected String resourceDomain;

@Shadow
@Final
@Mutable
protected String resourcePath;

@Inject(method = "<init>(I[Ljava/lang/String;)V", at = @At("RETURN"))
private void reinit(int what, String[] id, CallbackInfo ci) {
this.resourceDomain = IdentifierCaches.NAMESPACES.deduplicate(this.resourceDomain);
this.resourcePath = IdentifierCaches.PATH.deduplicate(this.resourcePath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.jellysquid.mods.hydrogen.common.dedup;

import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;

import java.util.Objects;

public class DeduplicationCache<T> {
private final ObjectOpenCustomHashSet<T> pool;

private int attemptedInsertions = 0;
private int deduplicated = 0;

public DeduplicationCache(Hash.Strategy<T> strategy) {
this.pool = new ObjectOpenCustomHashSet<>(strategy);
}

public DeduplicationCache() {
this.pool = new ObjectOpenCustomHashSet<>(new Hash.Strategy<T>() {
@Override
public int hashCode(T o) {
return Objects.hashCode(o);
}

@Override
public boolean equals(T a, T b) {
return Objects.equals(a, b);
}
});
}

public synchronized T deduplicate(T item) {
this.attemptedInsertions++;

T result = this.pool.addOrGet(item);

if (result != item) {
this.deduplicated++;
}

return result;
}

public synchronized void clearCache() {
this.attemptedInsertions = 0;
this.deduplicated = 0;

this.pool.clear();
}

@Override
public synchronized String toString() {
return String.format("DeduplicationCache ( %d/%d de-duplicated, %d pooled )",
this.deduplicated, this.attemptedInsertions, this.pool.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package me.jellysquid.mods.hydrogen.common.dedup;

public class IdentifierCaches {
public static final DeduplicationCache<String> NAMESPACES = new DeduplicationCache<>();
public static final DeduplicationCache<String> PATH = new DeduplicationCache<>();
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.patcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
"performance.RenderChunkMixin_OptimizeSpecialTileEntities",
"performance.RenderEntityItemMixin_EntityCulling",
"performance.RenderGlobalMixin_LimitVisGraphScan",
"performance.ResourceLocation_Deduplicate",
"performance.ResourcePackRepositoryMixin_FasterSearching",
"performance.SimpleReloadableResourceManager_OnlyRefreshNecessaryListeners",
"performance.TexturedQuadMixin_BatchDraw",
Expand Down

0 comments on commit eb19b29

Please sign in to comment.