Skip to content

Commit

Permalink
Core: Speed up fill_restrictive item_pool pop loop
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Mysteryem committed Jan 21, 2025
1 parent edacb17 commit b755759
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def fill_restrictive(multiworld: MultiWorld, base_state: CollectionState, locati
items_to_place.append(reachable_items[next_player].pop())

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

maximum_exploration_state = sweep_from_pool(
Expand Down

0 comments on commit b755759

Please sign in to comment.