Memoize creative tab content building per-tab
This should greatly reduce lag spikes experienced when opening the creative inventory with a mod like EMI installed, as the creative tabs will not be rebuilt a second time
This commit is contained in:
parent
75f0944a87
commit
4fe04025ef
|
|
@ -0,0 +1,28 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.memoize_creative_tab_build;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(CreativeModeTab.class)
|
||||
public class CreativeModeTabMixin {
|
||||
@Unique
|
||||
private CreativeModeTab.ItemDisplayParameters mfix$oldParameters;
|
||||
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason Vanilla already does similar memoization in the CreativeModeTabs class, but mods often have to bypass
|
||||
* it due to wanting to build the tab contents before search trees are populated. By memoizing at this lower level,
|
||||
* we can skip the expensive work of computing the tab contents multiple times while not affecting the logic in
|
||||
* CreativeModeTabs.
|
||||
*/
|
||||
@WrapMethod(method = "buildContents")
|
||||
private synchronized void buildContentsIfChanged(CreativeModeTab.ItemDisplayParameters parameters, Operation<Void> original) {
|
||||
if (mfix$oldParameters == null || mfix$oldParameters.needsUpdate(parameters.enabledFeatures(), parameters.hasPermissions(), parameters.holders())) {
|
||||
original.call(parameters);
|
||||
}
|
||||
mfix$oldParameters = parameters;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user