Skip to content

Cache ItemStacks to improve performance#1249

Open
Swedz wants to merge 2 commits intoAztechMC:1.21.xfrom
Swedz:cache-itemstacks
Open

Cache ItemStacks to improve performance#1249
Swedz wants to merge 2 commits intoAztechMC:1.21.xfrom
Swedz:cache-itemstacks

Conversation

@Swedz
Copy link
Collaborator

@Swedz Swedz commented Mar 11, 2026

This simply caches ItemStacks in ConfigurableItemStack and SlotItemHandler to reduce the unnecessary initializations. This should be safe, since the result of IItemHandler#getStackInSlot must not be modified.

This also includes a very minor improvement in ItemVariantImpl that reduces the unnecessary copying of ItemStacks - I'm not too sure that is contributing very much here though. This can be dropped if deemed unnecessary.

Profile reports courtesy of PupleDino on discord:

Spark Report (Before)
image

Spark Report (After)
image

In this case, it seems to yield a roughly 10ms/t reduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant