-
-
Notifications
You must be signed in to change notification settings - Fork 60
- #842 Small performance optimisations for the BuyStuff JoyGiver #843
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
Open
simplyWiri
wants to merge
2
commits into
OrionFive:develop
Choose a base branch
from
simplyWiri:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Won't this mean they'll buy the same things all the time?
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.
Yes - You can do something like randomize the index within the array of items - and wrap around if you reach the end (incrementing
ntimes) if you would like that behaviour. I'd drop the second commit and re-write if you are interested, the first commit can be CP'd directly, imo.Second commit is just an example of why this function is (still) slow after my first change, and offers a potential approach to making it faster. I don't think its a huge deal - but with large shopping areas, this causes the game to stutter noticeably.
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 don't understand what the idea behind the wrapping around is. I do understand the need for fixing the performance, though.
I find it quite important that they make a random selection. So if you could commit a fix for that, it'd be great. I suppose with this code it shouldn't be an issue if duplicate elements are picked by random, so that should allow for a fairly cheap solution.
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.
Basically, you have some (semi-ordered) list
things. And you want to selectnrandom items from the list.We want to avoid calling the
IsValidcheck super frequently, and if we do - lets try to have it in semi-contiguous memory. To choose a random item, we can pick a random starting index, and increment from there, if our random index, is say - the second last index. We then wrap around to the start of the array again.This ensures that (worst case) we still check every item in
things, but in the best case - we can early out much faster and dramatically reduce the number ofIsValidcalls.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.
Change here: https://github.com/OrionFive/Hospitality/compare/5a206d50ff177f03ad824600baac449f8d117f22..ed4e3599c3b48f071d71dd7e0a0c0d6f9e4b5b8b
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.
Can you add some fail safes? I feel if
thingsis empty or less than 5, we might get issues. Or have you tested that?