Tetra

Tetra

12M Downloads

Modular items' rendering has a severe effect on FPS

PieKing1215 opened this issue ยท 3 comments

commented

Observed Behaviour
Whenever several modular items are rendered in inventories there is a severe performance hit.
In a modpack I'm playing with friends, having ~5 tetra items on our hotbars incurs a ~50 FPS penalty at best.
Since modpacks are a horrible way to test things, I also tested with just Tetra, and the problem persists, though it only seems to be as bad when the inventory is open.

For example with no other mods (this is with vsync on and the F3 screen open, but the problem still happens with either/both off):
I get 144 FPS looking in the creative inventory with no items in my inventory.
I get ~130 FPS looking in the creative inventory with my hotbar full of vanilla iron pickaxes.
I get ~60 FPS looking in the creative inventory with my hotbar full of Tetra iron pickaxes.
I get ~48 FPS if I hover over one of the pickaxes.
Even if I have just 1 of these pickaxes, hovering over it drops my FPS to ~75.

Outside of the inventory, I get 144 FPS with no items, 144 FPS with a hotbar of vanilla pickaxes, and ~100 FPS with a hotbar of the Tetra pickaxes.

image

Expected Behaviour
I would expect less of a performance hit from the modular items, though it makes sense that there would be some.

Minimal setup needed to reproduce

  • Forge version: 1.15.2 - 31.2.33
  • Tetra version: 2.18.1
  • Tetra configuration: https://pastebin.com/YSSjqvTJ (iirc it's default) (are there any options that would affect this?)
  • Other mods: None (other than mgui)

(Tested on an Intel i7-8750H + RTX 2060)

Steps to reproduce

  1. Create a new singleplayer world
  2. Open inventory and record FPS
  3. Make a Tetra tool and fill hotbar with it
  4. FPS should be noticeably lower outside the inventory and even worse inside.
commented

(I'm mostly just adding this information for reference but feel free to do whatever you want with it.)

I've done some testing by building from source and adding some profiling, and I found that some of the major performance hits come from ItemModular::getMaxDamage and ItemModular::hasEffect.

getMaxDamage is especially bad for performance, since it needs to iterate through a large tree of modules and tweaks (which it needs to do in order to be correct). To test its effect, I put in a cache which gets marked as dirty whenever the damage changes. This alone adds ~25 FPS because it doesn't need to recalculate the max durability several times per item per frame.

Adding a similar cache for hasEffect works pretty much the same, adding ~10 FPS in my testing.

I'm sure you know that a large performance boost could be gained by caching other things as well, though these two were the biggest I could easily work around.

I've also come to the conclusion that the largest contributor to performance is actually drawing the item model in the gui. Disabling the model by returning originalModel in ModularOverrideList::getModelWithOverrides (which causes the item slot to render nothing), adds (very roughly) 60 FPS, causing the whole performance problem to be only a ~20 FPS hit in normal scenarios (where you have just a few Tetra tools).
Obviously, not rendering the tools is not a very good solution, but I'm not particularly familiar with how item rendering works so I still have to look into this further.

Unfortunately, since the source code in this repo is out of date (#208), I can only really test this up to 2.13.0 using the actual source.

commented

I really like the idea of caching the stats and effects. My plan was to store those in the itemstack but caching them is more efficient, easier to implement and less error prone!

The item model contains way more quads than it has to (60+ per texture), that could probably be cut down significantly. Some items (like the bow) also calculates item effects to figure out which model it should show, which makes it even slower.

Apologies for the outdated source, I need to cut down on stress and publishing the code is low-key stress for me ๐Ÿ˜…. I'll plop it up as soon as I get better!

commented

Added caching for most item stats in 3.0.0