Skip to content

Commit 2ba08f4

Browse files
MysteryemExempt-Medic
authored andcommitted
Core: Speed up fill_restrictive item_pool pop loop (ArchipelagoMW#4536)
* Core: Speed up fill_restrictive item_pool pop loop Items from `reachable_items` are placed in last-in-first-out order, so items being placed will be towards the end of `item_pool`, but the iteration to find the item was iterating from the start of `item_pool`. Now also uses `del` instead of `.pop()` for an additional, tiny, performance increase. It is unlikely for there to be a noticeable difference in most cases. Only generating with many worlds with a high percentage of progression items and fast access rules is likely to see a difference with this change. --skip_output generation of 400 template A Hat in Time yamls with progression balancing disabled goes from 76s to 43s (43% reduction) for me with this patch. This placed 43200 progression items out of 89974 items total (48% progression items). * Fix comment typo "be" was missing. --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
1 parent 0cbba2f commit 2ba08f4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Fill.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ def fill_restrictive(multiworld: MultiWorld, base_state: CollectionState, locati
7575
items_to_place.append(reachable_items[next_player].pop())
7676

7777
for item in items_to_place:
78-
for p, pool_item in enumerate(item_pool):
78+
# The items added into `reachable_items` are placed starting from the end of each deque in
79+
# `reachable_items`, so the items being placed are more likely to be found towards the end of `item_pool`.
80+
for p, pool_item in enumerate(reversed(item_pool), start=1):
7981
if pool_item is item:
80-
item_pool.pop(p)
82+
del item_pool[-p]
8183
break
8284

8385
maximum_exploration_state = sweep_from_pool(

0 commit comments

Comments
 (0)