-
Notifications
You must be signed in to change notification settings - Fork 9
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
remove o(n^2) operation from NumberedObjectCollection #563
remove o(n^2) operation from NumberedObjectCollection #563
Conversation
This depends on #539 |
There is still an O(N^2) call to
|
I can't replicate this O(N^2) behavior. I wonder if the wrong version of MontePy was used in the test. |
Upon further examination this was a problem with my tests. If you look at the profile results in the CI, |
Two small changes to make. |
No change in memory usage (duh), but went from 27.6 seconds to 26.7 seconds for this improvement. This is a 3% reduction for the "big model". Though this is a low cost O(N^2) operation, and the saving should scale accordingly. |
Description
As described in #556 there was an O(N^2) operation for appending N items to a
NumberedObjectCollection
. This was becauseself.numbers
(which is an O(N) generator) was checked every append. This was fixed by:check_number
__num_cache
explicitly iff this problem is linked to a problem._update_number
that updates__num_cache
appropriately when a number is changed.Numbered_MCNPObject
instances run_update_number
if they are attached a problem. This is why__num_cache
is trusted in this case.This doesn't remove all bottlenecks and get us to O(N) time, but it does make
append
no longer a bottle neck as can be seen in the profiling results.Don't review this until #539 is merged because this is built off of that branch.
Fixes #556
Checklist