Sandwichable

Sandwichable

1M Downloads

Performance issue when item of a slightly enlarged sandwich is being rendered

SRAZKVT opened this issue ยท 3 comments

commented

just like any other person, a very good friend and myself tried to make a sandwich as large as possible, but we started noticing something : despite having only one type of item in it (melon slices), we had performance issues, not even when holding the sandwich in our hand, but when it is just rendered in a chest, in the inventory or in the hotbar. One way to fix that i would see is to keep in memory which item type is the last that has been rendered, and only render following items if they are different. This way if multiple items of the same type are rendered, they aren't rendered each time. Doubt it will matter unless another madlad creates a sandwich with a thousand melon slices though.

the sandwich :
sandwich1

without the sandwich in the hotbar :
sandwich2

with the sandwich in the hotbar (not held) :
sandwich3

commented

You misunderstand how rendering items works, try dropping a thousand stacks of melon items and see what happens to your performance in spite of it only being "one type of item"

Trying to change the way the sandwich item is rendered in the inventory would also break the way it is rendered in the hand

I have been considering using Flywheel to optimize the rendering of sandwiches in a future update

commented

The issue isn't that rendering the actual model is expensive, we expected that. The issue is caused by the way you're rendering the actual item in the inventory, notice how there are a lot of melon slices rendered over the top of the bread in the last screenshot, which only happened after adding enough of them. They're also rendering over inventory tooltips for some reason.

I'm guessing you're rendering all the individual items in the sandwich in the inventory stacked for some reason, the proposed solution is that you only need to render the topmost instance of each item type in the sandwich only. Though it wouldn't fix someone adding a lot of different item types to cause lag instead, you'd probably need to implement some simple culling for that (for example in our case here, there's no reason why any melon slices should be rendered in the inventory at all since their sprite is smaller than the bread).

I'm not sure why you made the comparison to spamming item entities either unless you misread the issue text; we aren't surprised that rendering the models causes issues, we're surprised that just having the sandwich in the inventory causes issues due to however you've decided to render it.

commented

The wasteful item icon rendering would be complicated to fix for two reasons
First off, that means rotating the item model (i.e. in the model file) would reveal an incomplete sandwich.
Secondly, since the icon, held item, and dropped item use the same model, it would be appear incomplete in all those ways unless I special cased it.
Overall I would like to explore flywheel and other more elegant ways of optimizing sandwich rendering (both in world and in gui) rather than come up with some patchy solutions.