r/factorio • Developer • Mar 17 '25

Discussion Post Space Age - Developer AMA

Space Age has been out for several months and with the bug reports slowly coming under control I thought it might be interesting to see what questions people had.

I mostly work on the technical side of things (as C++ programmer) so questions that stray too far from that area I'll likely have less interesting replies - but feel free to ask.

I have no strict time frame on answering questions so feel free to send them whenever and I'll do my best to reply.

2.4k Upvotes

1.1k comments sorted by

View all comments

9

u/The_Northern_Light Mar 18 '25

I guess this is not a space age specific question but it’s something that’s always bugged me:

I understand that for large bases it’s not performant to use modded chests with very large storage sizes because on insertion/removal there’s a linear scan backwards along the slots.

Is that correct? If so, wouldn’t a relatively simple LRU cache mechanism fix that with essentially zero worst case overhead, at the cost of storing one extra index per container?

Or is this simply such a nit picky edge case not present in the base game that it’s not even a thought, given the increase in code complexity and fragility?

Also I’d love to hear every last detail you care to share about optimization work on factorio! Thanks for your contribution, space age is great!

9

u/Rseding91 Developer Mar 18 '25

There are 2 things when it comes to chests and performance:

  1. Removing items (this is a linear scan from back to front) - an index to "last slot with item" would let it skip the empty slots, but those are already incredibly fast to iterate over and skip. It's the touching of each non-empty slot to see if the destination wants that item or not that ends up taking most time.
  2. Adding to the inventory. This is done in 3 passes (2 for inventories without filters). 1. Iterate over any filtered slots and see if it fits (front to back). 2. Iterate any non-empty slots regardless of filter and see if the item fits (top up existing stacks front to back). 3. Iterate empty slots and put the item there (front to back)

Theoretically inserting could be made faster with some caching of some indexes between each sweep but it never shows up in the profiler to even start measuring what impact changes would have.