From f885819e7beba5046bef229c7682b1d115bda347 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Thu, 30 Jan 2025 05:05:51 +0000 Subject: [PATCH 1/2] Core: Better scaling explicit indirect conditions When the number of connections to retry was large and `queue` was large `new_entrance not in queue` would get slow. For the average supported world, the difference this change makes is negligible. For a game like Blasphemous, with a lot of explicit indirect conditions, generation of 10 template Blasphemous yamls with `--skip_output --seed 1` and progression balancing disabled went from 19.0s to 17.9s (5.9% reduction in generation duration). --- BaseClasses.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index e19ba5f7772e..2943d7812848 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -776,9 +776,11 @@ def _update_reachable_regions_explicit_indirect_conditions(self, player: int, qu self.path[new_region] = (new_region.name, self.path.get(connection, None)) # Retry connections if the new region can unblock them - for new_entrance in self.multiworld.indirect_connections.get(new_region, set()): - if new_entrance in blocked_connections and new_entrance not in queue: - queue.append(new_entrance) + entrances = self.multiworld.indirect_connections.get(new_region) + if entrances is not None: + entrances = entrances.intersection(blocked_connections) + entrances.difference_update(queue) + queue.extend(entrances) def _update_reachable_regions_auto_indirect_conditions(self, player: int, queue: deque): reachable_regions = self.reachable_regions[player] From 71b3bb20a0a84625114bdb5957d9cafac252b8a9 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Fri, 31 Jan 2025 01:44:05 +0000 Subject: [PATCH 2/2] Create a new variable for the new set created from the intersection --- BaseClasses.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 2943d7812848..e0f86f7d8361 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -778,9 +778,9 @@ def _update_reachable_regions_explicit_indirect_conditions(self, player: int, qu # Retry connections if the new region can unblock them entrances = self.multiworld.indirect_connections.get(new_region) if entrances is not None: - entrances = entrances.intersection(blocked_connections) - entrances.difference_update(queue) - queue.extend(entrances) + relevant_entrances = entrances.intersection(blocked_connections) + relevant_entrances.difference_update(queue) + queue.extend(relevant_entrances) def _update_reachable_regions_auto_indirect_conditions(self, player: int, queue: deque): reachable_regions = self.reachable_regions[player]