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

Stardew Valley: Improve default options performances by grouping rules before counting them #2984

Conversation

Jouramie
Copy link
Contributor

@Jouramie Jouramie commented Mar 18, 2024

What is this fixing or adding?

This improves performances when filling Stardew Valley seed. The biggest gain is when playing with Museumsanity set to milestones (default), which improves performances by ~10%.

image

This works because a lot of artifacts have the same condition. Some rules only need to be evaluated once, but count toward multiple artifacts.

How was this tested?

Ran our performance tests, filling ~80 seeds with multiple settings.

If this makes graphical changes, please attach screenshots.

N/A

@github-actions github-actions bot added the waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. label Mar 18, 2024
@agilbert1412 agilbert1412 added is: enhancement Issues requesting new features or pull requests implementing new features. is: refactor/cleanup Improvements to code/output readability or organizization. is: maintenance Regular updates to requirements and utilities that do not fix bugs or change/add features. and removed is: enhancement Issues requesting new features or pull requests implementing new features. is: refactor/cleanup Improvements to code/output readability or organizization. labels Mar 18, 2024
Copy link
Collaborator

@agilbert1412 agilbert1412 left a comment

Choose a reason for hiding this comment

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

Lots of that is Python black magic, but none of it seems wrong. And the gains are pretty cool!

worlds/stardew_valley/test/stability/TestStability.py Outdated Show resolved Hide resolved
worlds/stardew_valley/stardew_rule/state.py Outdated Show resolved Hide resolved
worlds/stardew_valley/stardew_rule/base.py Outdated Show resolved Hide resolved
@Jouramie Jouramie marked this pull request as draft March 18, 2024 13:02
@Jouramie
Copy link
Contributor Author

Moving this back to draft because the change I did to support 3.8 seems to drop performances. I'll have to check again.

Copy link
Collaborator

@agilbert1412 agilbert1412 left a comment

Choose a reason for hiding this comment

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

I approve the code as-is, but if the performance gain is not there anymore due to 3.8, I agree with drafting the PR

@black-sliver
Copy link
Member

damn you python 3.8 I wanted to use slots :(

if you can measure an actual performance gain, this can be done using kwarg unpacking

if sys.version_info >= (3,10,0):
     dataclass_args = { "slots": True }
else:
     dataclass_args = {}

@dataclass(..., **dataclass_args)
class SomeClass:
    ...

Slots can be slower though. If they are on par, going slots is the better choice for memory.

Mom can we have python? We already have python at home son.

You can monkey patch the counter for py<3.10 and then enjoy the fast implementation on 3.10. Depending on how often the counter changes, and how often it is read, you could also cache the total in the counter.

@Jouramie
Copy link
Contributor Author

Slots can be slower though. If they are on par, going slots is the better choice for memory.

I'll mesure it. I'm not even sure it's used at its full capacity because of the inheritance.

You can monkey patch the counter for py<3.10 and then enjoy the fast implementation on 3.10. Depending on how often the counter changes, and how often it is read, you could also cache the total in the counter.

The counter is not expected to change, so I'll just cache it. In the end, the 3.10 probably won't change anything.

@Jouramie Jouramie marked this pull request as ready for review March 18, 2024 21:14
@Jouramie
Copy link
Contributor Author

Turns out I was comparing runs against the 6.x.x branch, which also has more performance improvements, still being worked on. I updated the screenshot of the benchmarking comparing this branch against main, and we can see the improvement is still there.

I will measure and add slots if it improves performances significantly enough in a different PR.

@Jouramie
Copy link
Contributor Author

Jouramie commented Mar 19, 2024

And turns out again that this is a huge bug in my implementation, because evaluate_while_simplifying return a tuple and not a boolean. Anyway, the performance gains are not as much as I first thought, but this still generates the default settings faster.

@Jouramie Jouramie force-pushed the StardewValley/count-speed-improvement branch from d88c0a7 to a443d9b Compare March 22, 2024 02:34
@agilbert1412
Copy link
Collaborator

Is this now included in #3478 ? @Jouramie if so can you close this one?

@Jouramie
Copy link
Contributor Author

Jouramie commented Jun 7, 2024

Yes it's included, good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is: maintenance Regular updates to requirements and utilities that do not fix bugs or change/add features. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants