Inserter/chest Optimization idea
Posted: Sat Jul 16, 2022 2:45 am
The problem right now is when an inserter wants to insert or remove an item, it has to check each slot until it finds a valid one, right? What if the chest inventory was split into three arrays- full slots, empty slots, and partially filled slots?
It works like this:
When an item needs to be inserted, it can check the list of partially filled slots first, which will be much smaller than the other two lists. If it can't fit the item type in, then it goes to the first slot in the empty slot list.
When an item needs to be taken out, it can check the list of partially filled slots first, then the list of filled slots. This can be expensive since it needs to iterate on the list of filled slots and that can potentially be large, but after it does so the item removed causes that slot to be a partial slot, which means the next removal is much faster.
Doing it this way means in most cases, the inserter only has to look at a list of 10 or less slots.
There is a side effect that if there are empty slots near the top of the container they won't be filled until partially filled slots are filled up. I don't think that will break any automation though.
It works like this:
When an item needs to be inserted, it can check the list of partially filled slots first, which will be much smaller than the other two lists. If it can't fit the item type in, then it goes to the first slot in the empty slot list.
When an item needs to be taken out, it can check the list of partially filled slots first, then the list of filled slots. This can be expensive since it needs to iterate on the list of filled slots and that can potentially be large, but after it does so the item removed causes that slot to be a partial slot, which means the next removal is much faster.
Doing it this way means in most cases, the inserter only has to look at a list of 10 or less slots.
There is a side effect that if there are empty slots near the top of the container they won't be filled until partially filled slots are filled up. I don't think that will break any automation though.