Repository navigation
Movegoods fix - #1655
Movegoods fix#1655ab9rf wants to merge 6 commits into
Conversation
rewrite the UI and backend processing for `movegoods` to avoid repeatedly retraversing the item list while (un)marking items for trade also use a coroutine to ensure the frame pump continues to run when (un)marking a large number of items fixes DFHack/dfhack#6050
item scan in the test fort i am using was taking ~6s. these changes trim it to about ~2s which is a significant improvement will look into why dfhack.item.* methods are so slow to invoke (~95-100 microseconds per call) - there might be a core issue here that can be mitigated but that'll be done separately
mark preservation was not working correctly in conjunction with item grouping, caused a CI test failure
SilasD
left a comment
There was a problem hiding this comment.
generally, the scan_queued looks over-engineered and a bit confusing.
- as far as I can tell,
scan_queuedis a hash table that can be empty, or can contain a single key, eithertrueorfalse, with a value oftrue. that key is the value to use forinside_containersfor the queued scan. - then there is a separate
scanhash table, that contains (at least) a keyinside_containerswith the value being used on the currently in-progress scan. - the current
inside_containerssetting is sometimes taken directly fromscan, and sometimes passed into functions as a parameter.
it all feels a bit inconsistent. and clunky. I'm sure it works though.
if you do choose to re-engineer it, perhaps settle on the scan hash table and all the keys it can use (I think this is currently only inside_containers), and make scan_queued into a table (or preferrably a list) of pending scan settings.
then starting the next scan is just a case of getting the next scan parameters from the table or list.
Something like
local next_scan_settings = { inside_containers = inside_containers }
table.insert(scan_queued, next_scan_settings)and
self.scan = table.remove(scan_queued, 1)would be ideal, as it would make the thing into a real queue.
(note that you can table.remove() from an empty table; it returns nil instead of throwing.)
this would still be over-engineered, but it would be clearer and would be trivially extendable to support scan parameters other than inside_containers. the current implementation would require rewriting to support other scan parameters.
neat coroutine idea. I can't quite tell if the game is forced paused during the asynchronous processing, so I'll just mention that it needs to be.
(later) especially as the code keeps references to items across yields.
I'm burned out, but I hope to get back to this.
| local pos = item.pos | ||
| return pos.x ~= -30000 and pos or nil |
There was a problem hiding this comment.
reminder that this is returning a live reference to an item's internal fields.
if that item goes away over a yield(), it'll be a stale reference.
I'm not alert enough right now to check if that's a problem.
removed some unnecessary bypasses based on better empirical profiling data also fixed a defect related to tracking the "risky" indicator this version loads around 80,000 items in less than two seconds (about a second faster than the previous evolution) and has no discernable lag when selecting or deselecting even large numbers of items
rewrite the UI and backend processing for
movegoodsto avoid repeatedly retraversing the item list while (un)marking items for tradealso use a coroutine to ensure the frame pump continues to run when (un)marking a large number of items
additional optimizations added to try to reduce the startup time especially in large forts
fixes DFHack/dfhack#6050