-
Notifications
You must be signed in to change notification settings - Fork 777
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
Stardew Valley: Improve default options performances by grouping rules before counting them #2984
Conversation
There was a problem hiding this 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!
Moving this back to draft because the change I did to support 3.8 seems to drop performances. I'll have to check again. |
There was a problem hiding this 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
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. 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. |
I'll mesure it. I'm not even sure it's used at its full capacity because of the inheritance.
The counter is not expected to change, so I'll just cache it. In the end, the 3.10 probably won't change anything. |
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. |
And turns out again that this is a huge bug in my implementation, because |
use slots add group to has rules reach any checks if any are already accessible remove hardcoded true from count
…d of the output...
d88c0a7
to
a443d9b
Compare
Yes it's included, good catch! |
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%.
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