Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use ItemIdentifierStack in ItemStackRenderer #40

Merged
merged 2 commits into from
May 19, 2024

Conversation

szuend
Copy link

@szuend szuend commented May 18, 2024

... instead of ItemStack and cache EntityItem.

The current code has an entiyItem field on ItemStackRenderer. But for the use case of rendering items in pipes we only use a single ItemStackRenderer so the entityItem is actually never re-used and we create a fresh instance. This means in essence we create a new EntityItem instance every time an item travels down a pipe.

To optimize for the renderInWorld case of a single ItemStackRenderer, we cache one EntityItem for each item. To aid in this we refactor ItemStackRenderer to use an ItemIdentifierStack instead of an ItemStack. Most users of ItemStackRenderer use IdentifierStacks anyway.

The result is a small (but noticable) bump in FPS when lots of different items are traveling at the same time and less pressure on the GC for all the temporary EntityItems.

... instead of ItemStack and cache EntityItem.

The current code has an `entiyItem` field on ItemStackRenderer.
But for the use case of the rendering items in pipes we only
use a single ItemStackRenderer so the `entityItem` is
actually never re-used and we create a fresh instance. This means
in essence we create a new `EntityItem` instance every time an
item travels down a pipe.

To optimize for the `renderInWorld` case of a single
ItemStackRenderer, we cache a single EntityItem used for
rendering each item. To aid in this we refactor ItemStackRenderer
to use an `ItemIdentifierStack` instead of an `ItemStack`. Most
users of `ItemStackRenderer` use IdentifierStacks anyway.

The result is a small bump in FPS when lots of different items
are traveling at the same time and less pressure on the GC for
all the temporary `EntityItem`s.
@szuend
Copy link
Author

szuend commented May 18, 2024

I can split it into two PRs for easier review if preferred.

@Dream-Master Dream-Master requested a review from a team May 18, 2024 08:06
@OneEyeMaker
Copy link

Please, use consistent naming for item stacks and item identifiers. I got myself confused a few times while reading code before I found that itemstack and itemStack are different things...

@szuend
Copy link
Author

szuend commented May 19, 2024

Good idea, thanks for the review!

@Dream-Master Dream-Master merged commit b020c30 into GTNewHorizons:master May 19, 2024
2 checks passed
@szuend szuend deleted the cache-entity-item branch May 19, 2024 16:18
szuend added a commit to szuend/LogisticsPipes that referenced this pull request May 20, 2024
For doRenderItem there is no need to convert first to an ItemStack
and then back to an ItemIdentifierStack on the hotpath if we can just
pass the ItemIdentifierStack directly.

This is a follow up to GTNewHorizons#40.
boubou19 pushed a commit that referenced this pull request May 20, 2024
…#44)

For doRenderItem there is no need to convert first to an ItemStack
and then back to an ItemIdentifierStack on the hotpath if we can just
pass the ItemIdentifierStack directly.

This is a follow up to #40.
Dream-Master pushed a commit that referenced this pull request May 20, 2024
* refactor: Use ItemIdentifierStack in ItemStackRenderer

... instead of ItemStack and cache EntityItem.

The current code has an `entiyItem` field on ItemStackRenderer.
But for the use case of the rendering items in pipes we only
use a single ItemStackRenderer so the `entityItem` is
actually never re-used and we create a fresh instance. This means
in essence we create a new `EntityItem` instance every time an
item travels down a pipe.

To optimize for the `renderInWorld` case of a single
ItemStackRenderer, we cache a single EntityItem used for
rendering each item. To aid in this we refactor ItemStackRenderer
to use an `ItemIdentifierStack` instead of an `ItemStack`. Most
users of `ItemStackRenderer` use IdentifierStacks anyway.

The result is a small bump in FPS when lots of different items
are traveling at the same time and less pressure on the GC for
all the temporary `EntityItem`s.

* Use itemIdentifierStack vs itemStack consistently in ItemStackRenderer.java

(cherry picked from commit b020c30)
Dream-Master pushed a commit that referenced this pull request May 20, 2024
…#44)

For doRenderItem there is no need to convert first to an ItemStack
and then back to an ItemIdentifierStack on the hotpath if we can just
pass the ItemIdentifierStack directly.

This is a follow up to #40.

(cherry picked from commit 02af086)
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.

3 participants