Optimization: Crafting material inventory insertion

I’ve noticed that if I intentionally leave a bunch of free space in the left side of my inventory, and then pick up a bunch of shards, they fill in relatively quickly. This leads me to believe the stutter issue comes from the method used to find an open inventory space for an item to be added to the inventory.

Under normal gameplay, the game visibly lags for every player regardless of their machine when picking up crafting materials because each item seems to check every inventory slot from top to bottom left to right to find an open slot. Then the next shard starts the search from scratch, when it could resume from where the last shard was just inserted into the player’s inventory. I assume it starts from scratch, because a full inventory with some left-side space is faster than an the same inventory with right side space.

However, even then there’s something deeply flawed with our hypothetical findOpenInventorySlotOfSize call if just a few thousand invocations cause it to lag for 20-25+ frames. If you pick up more than 6 or 7 shards the lag gets noticeable, and at 15+ it’ll just straight up get you killed if there are enemies nearby.

The inventory is only 8x14, so when filling the last column each shard would check 104 - 111 cells each, which at 16 pickups for the last two columns would only be around 1,600 invocations to our hypothetical findOpenInventorySlotOfSize(1,1) method, which shouldn’t take 300+ms to execute.

Still, caching the occupied slots when mass collecting crafting materials would cut the number of invocations to a maximum of 112 for the entire collection to be added to the inventory, even if the underlying findOpen…Slot method is a little on the hefty side.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.