CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
9.73k stars 4.05k forks source link

Analyzing the perfomance of hot dogs #73502

Open GuardianDll opened 2 weeks ago

GuardianDll commented 2 weeks ago

Describe the bug

While playing the game, i made a lot of hotdogs, put them all in the same vehicle tile, and found my PC needs at least two seconds to open AIM with said hotdogs image Perfomance analyzer shows enormous amount of hits in uncraft components image Further discussion and @RenechCDDA making suggestions is here, tho i barely undestand where exactly the problem is, but i guess the game, for some reason, scan all the food to check their disassembly components

Attach save file

Freedom-trimmed.tar.gz

Steps to reproduce

open the save file open AIM pointing to south west ↙ notice the lag

Expected behavior

no lag

Screenshots

No response

Versions and configuration

Additional context

No response

MNG-cataclysm commented 1 week ago

This has to be one of, if not the most ridiculous error I've ever heard of.

RenechCDDA commented 1 week ago

https://github.com/CleverRaven/Cataclysm-DDA/blob/64321d67f81ae7a0ac1fa75e26921d3e734bb73f/src/advanced_inv_area.cpp#L287-L292

So basically the problem is here. As AIM starts assembling its stacks, it checks items against every existing item in every stack. In the provided save, there are ~600 hot dogs laying around in a pile of 482 and then two piles of ~50. So once the pile of 482 is assembled in <100ms, the remaining piles start getting assembled... one item at a time. So it picks up one new hot dog, checks it against 482 existing hot dogs and makes the very expensive component comparison for each of them. And then it does it again. And again. And again. Until it has checked it against all 482 of the existing hot dog stack, before deciding to put it in a new stack. Repeat for hot dogs 2-52.

What I do not understand is why it insists on doing it against every item in the stack. Since these stacks were already built by AIM, we already know that they will not stack once we hit the first one which doesn't stack.

It is a very deliberate design decision, and it's easy enough to tear down, but why?