Mekanism Generators

Mekanism Generators

97M Downloads

[Small Optimization] FastUtilMaps allows to remove StackWrappers

Speiger opened this issue ยท 3 comments

commented

Not an issue but a small feature you should be maybe aware of this is a thing since 1.12 but I found out about it when 1.16 came out. And it might benefit you too.

As you know ItemStacks aren't compareable by default and a HashMap would not find exact items.
FastUtil has a Map class "CustomHashMap/Set"
The CustomHashMap allows to provide a Strategy that has full control over the keys hashKey & equals function.
Allowing to Inject ItemStacks directly into the HashMap. Ofc Inserted Keys should be unique, but for reading you can use any ItemStack and don't have to create wrappers to make it work.

This should improve performance slightly and also reduce garbage creation massively.

I thought that knowledge may help a lot. Especially since Strategy is so customize able.

Anyways that's all. Have a Nice day.

commented

This is very interesting

commented

Yep, one of the reasons I included it into my FastUtil clone...

commented

I was vaguely aware of it given the fact that we do this for fluids in places, though I will need to rereview our uses of items at some point as a good number of them our wrappers exist strictly to copy the stack anyways given we need it to persist and not be able to just get modified if something else modifies the backing stack.