-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Change strains list to be sorted list in StrainSkill
#29990
Conversation
I'm feeling deja vu on this change... |
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 dunno.
List<double> strains; | ||
|
||
// If no saved strains - calculate them from 0, and save them after that | ||
if (savedSortedStrains == null || savedSortedStrains.Count == 0) |
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.
The zero-count part of this check is super confusing to me. What scenario is this supposed to handle..?
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.
This function is called whenever DifficultyValue
is called
So this covers pretty much every scenario except progressive calculations, preserving the same behavior as before (just straight up sort all the strains)
strains = peaks.OrderDescending().ToList(); | ||
|
||
savedSortedStrains = new List<double>(strains); |
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.
Is there a reason we're making two new lists 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.
Yes, strains
is what's gonna be returned with this function and modified in OsuStrainSkill
(in the diffspike nerf)
when savedSortedStrains
will be potentially used in next call
This is a bit of the performance loose if next call never happens, but I think one extra array copy will not make a big difference in that case
// Otherwise - just use saved strains | ||
else | ||
{ | ||
strains = new List<double>(savedSortedStrains); |
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.
Is there a reason for returning a new copy of the list each time? Is it going to be modified?
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.
strains
is going to be modified, yes
This is too complex for me, because it's hard to prove anything's correct. If this is the best that can be done code-wise then I prefer the existing implementation/performance. |
I'm going to close this one here. I don't have any suggestions, sorry, just... Keep things simple? |
This thing was made for optimisation, it cuts execution time for Timed Attributes calculation by 90% |
Maybe so, but I'm not merging optimisations at the cost of maintainability, and this is not something I'd want to maintain. Maybe there's a way you can refactor it into a custom object that's fit for this role like |
The reason why I made 4 conditions is because:
But I understand why you don't want to deal with it, as the performance issue is only really bad on graveyard 60 minutes map (2.5 minutes to wait for pp counter to init) |
I'm not saying the optimisations are bad or unnecessary. I'm saying the code is unmaintainable. I don't understand where the O(n^2) part is even coming from. Is it because progressive runs this code over and over again? That's an issue for another castle - the whole progressive thing is a gigantic hack and barely an MVP, and needs to be restructured from the ground up. That much was evident even in #29989 . Rather than hacking existing data structures, try to think about how things could be re-architected to accommodate for the new requirements. |
Sort is O(nlogn). This sort runs |
Only during progressive calc right? |
Yes |
Part of this PR - #29482
Sorted list is implemented from scratch because inbuilt C#
SortedList
class is not a List but Dictionary and therefore not suitable for this task.This is changing Summing time complexity for progressive calculation from O(n^2 * logn) to O(nlogn), significantly cutting the time of
TimedDifficultyAttributes
calculation.More detailed info is written on original PR.