Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HK: skip for loop #2390

Merged
merged 2 commits into from
Oct 29, 2023
Merged

HK: skip for loop #2390

merged 2 commits into from
Oct 29, 2023

Conversation

Berserker66
Copy link
Member

What is this fixing or adding?

just a tiny optimization I happened to notice when looking at region and location access

How was this tested?

wasn't

If this makes graphical changes, please attach screenshots.

@ScootyPuffJr1 ScootyPuffJr1 added the is: refactor/cleanup Improvements to code/output readability or organizization. label Oct 28, 2023
@@ -38,15 +37,13 @@ def hk_set_rule(hk_world: World, location: str, rule):


def set_rules(hk_world: World):
player = hk_world.player
world = hk_world.multiworld
player = hk_world
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes no sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how the frick did the unittests pass

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if player is not None:
            return [location for location in self._cached_locations if location.player == player]

accidental bug find moment
Screenshot_55

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on the new region cache and this would've crashed so that's good.

worlds/hk/Rules.py Outdated Show resolved Hide resolved
Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but approval of either @ThePhar or @BadMagic100 would be good

@BadMagic100
Copy link
Collaborator

Is this change really necessary? I know there is only the one region now but it seems silly to remove it for truly miniscule performance gains when it's likely to be added back anyway (I am assuming phar is planning to do something about regions at least)

@BadMagic100
Copy link
Collaborator

Or, I suppose to frame that question another way: how much would this actually be saving? I assume it to be miniscule (an extra function call per generation?) but in reality don't know any better and will ultimately defer to phar for an approval or denial

@alwaysintreble
Copy link
Collaborator

The proper refactor for what this is doing wouldn't look like the original method, as looping over every region will be even slower once HK has proper regions. Preferably, it'd add the shop locations to a cache on creation and just loop through that.

@BadMagic100
Copy link
Collaborator

Fair enough I suppose, but given that solution isn't the one implemented by this pr I'm not sure it really answers my question

@black-sliver
Copy link
Member

black-sliver commented Oct 29, 2023

The change to region caching in #2366 makes looping over "all locations for player" preferable over "all regions for player, and then all locations for those regions". It not only makes the code nicer, it also makes it faster, because the collection you want to iterate over already exists anyway.

Edit: Re-reading your comments, I feel like you misunderstand the change. We don't iterate "just one region" in the changed code, but instead we iterate over "all locations, ignoring the region it's from".

@BadMagic100
Copy link
Collaborator

Oh, you are right, this is what happens when I read code at midnight I suppose

@Berserker66 Berserker66 merged commit 9c80a7c into main Oct 29, 2023
21 checks passed
@Berserker66 Berserker66 deleted the hk_skip_loop branch October 29, 2023 18:54
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is: refactor/cleanup Improvements to code/output readability or organizization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants