-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Speed up autoremove search #2855
Conversation
dc50dc1
to
e78976b
Compare
Why use IEnumerables instead of explicit types? |
That's the only way I know to use |
I see, some weird Microsoft philosophy. |
No, this function now never generates an object with a collection inside of it. It runs pieces of the code inside the function to return each element as it's requested. If the calling code doesn't try to access the full sequence, then it won't be generated. |
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 confirm huuge performance improvements, and in addition, everything still works.
Thank you very much for finding and correcting the problem. CKAN is running much faster now. |
@shdwlrd, thanks for calling this problem to our attention! |
Problem
If you install many mods (200+) and click the checkbox to queue up one more to install, GUI takes a while to respond. I observed about 4.5 seconds with 282 mods, and a user reports 10-15 seconds with 363 mods.
Causes
A few
Console.WriteLine
statements revealed the following upon clicking:Apparent problems:
UpdateChangeSetAndConflicts
is called twice, only once is neededFindRemovableAutoInstalled
takes 1-1.5 seconds each time it is called (4x); this is most of the slownessLooking at
FindRemovableAutoInstalled
reveals several opportunities for improvements:CKAN/Core/Registry/Registry.cs
Lines 1131 to 1142 in a162c8b
FindReverseDependencies
is called on all installed modules, but it only needs to be called on auto-installed modules.All
call)FindReverseDependencies
traverses the whole reverse dependency tree, but we only care about enough entries to find one that isn't auto-installedChanges
UpdateChangeSetAndConflicts
is only called once per clickFindReverseDependencies
usesIEnumerable<>
andyield return
to generate its results lazily, so it will not traverse the entire reverse dependency tree if the calling code doesn't need it, avoiding costlyFindUnsatisfiedDepends
callsFindRemovableAutoInstalled
only checksFindReverseDependencies
for auto-installed modules, which should be a small fraction of the totalFindRemovableAutoInstalled
's linear array search is replaced with anIsSupersetOf
call to take advantage ofFindReverseDependencies
's new lazy evaluation (it will short circuit as soon as we find one rev dep that isn't auto-installed)In my test case, these changes brought the time to process a click from 4.5 seconds to 0.25 seconds, or about a 95% reduction. Mileage will vary with the details of installed mod lists.
@shdwlrd, if you'd like to try a test build with these changes:
Fixes #2846.