-
Notifications
You must be signed in to change notification settings - Fork 704
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
Core: Rewrite start inventory from pool code #3778
Core: Rewrite start inventory from pool code #3778
Conversation
Main.py
Outdated
multiworld.itempool[:] = new_items + old_items | ||
new_itempool.append(item) | ||
|
||
unfound_items_per_player = { |
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 feel like this section could all be inside an if overall_target:
and then at the end have:
else:
for player, target in target_per_player.items():
new_itempool += [multiworld.worlds[player].create_filler() for _ in range(target_per_player[player])]
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 do think this makes the code slightly more complicated, at probably little performance gain (The full iteration of the multiworld itempool is gonna be so much slower than anything that happens after it)
But I see your point. I'll think about it. I don't like the idea of just wrapping it in an extra indent, but maybe there is a different cute solution here.
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 timed it roughly, this change barely has any impact. The bottleneck is the exact code you're isolating:
for player, target in target_per_player.items():
new_itempool += [multiworld.worlds[player].create_filler() for _ in range(target_per_player[player])]
These lines take the most amount of time (after multiworld itempool iteration, which is the slowest part of the code).
The additional calculations you're avoiding with this change, barely make a dent.
I think in this case, I'd prefer to keep the code shorter / simpler, but open to be convinced still
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.
Yeah, I went and timed it myself with 10K players and it saved 0.0054 seconds on average over 20 trials (the range was 0.005-0.006) so... yeah, not worth
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 made a different improvement that should make this better in the worst cases
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.
One comment, otherwise the changes LGTM. Tested various configurations of start_inventory_from_pool and all behavior was identical to how it was before.
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.
New changes look good, did some more testing (including two cases I forgot about which would have failed previously...) and everything seems to work well.
I have now opted to remove I understand why it exists, not doing it is about 20% slower in the "average worst case" (lol), which could be considered worth it for a full iteration of the multiworld itempool. However, it
I can be convinced to bring it back, though. |
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.
code looks correct and cuts some corners that should improve performance but didn't actually run the code yet to see if i can catch any issues (medic seems to have ran through most of them tho lol)
I think the old code is pretty ugly and unpythonic
Here's my proposal for a better version
Even had some room to spare for comments, since I made it a couple lines shorter