-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Removed WeakReference<IHosts> already cleaned up by GC #4995
Conversation
In general, I guess it's ok and that it will work. But I am not 100% sure of having to do this every time a new IHost is Registered. Wonder if there's any performance impact because of this, but probably not, eventhough Register is called several times throughout the codebase. And in the other hand, after quickly looking into the code, I don't know where else could we do this. Since I am not familiar enough with IHost's I don't know if we could add a mechanism somewhere so that when we're about to stop using the IHost it can report to its "parent" that it's good to remove it from the _children List. Wonder if @eerhardt has any thoughts on this, since he has recently encountered this issue. |
Thanks for addressing my comment, and @eerhardt 's comment on multithreading. I wonder, did you found any performance difference when running this on the original issue scenario? |
@antoniovs1029 No worries! I did not see any performance difference when running this on master vs. on my own branch with these changes. I am currently running performance benchmark tests comparing the effect of my changes, and will share the results here when I'm done. |
I ran the Without changes:
With changes:
Explanation of Legends:
Here the results show no significant change in performance with these changes. Hence the changes of this PR do not add significant performance penalties. |
I wouldn't use ImageClassificationBench as a measurement here. Most of the time in that benchmark isn't spent in ML.NET code, but instead in TensorFlow. Instead, I would run the following: https://github.com/dotnet/machinelearning/blob/master/test/Microsoft.ML.Benchmarks/KMeansAndLogisticRegressionBench.cs Which should give a pretty good indication if anything has regressed. |
@eerhardt I ran the Without changes:
With changes:
|
MakeSentimentPredictions seems to be outside of the error range. Basically it is 10% slower (55ms to 60ms). Same for MakeBreastCancerPredictions. If you run it multiple times, are these numbers consistent? |
@eerhardt I have attached a .xlsx file containing the results for 5 consecutive runs for (https://github.com/dotnet/machinelearning/files/4430244/Benchmarks.Comparison.xlsx) Here is a summary averaged over 5 runs: I first ran 5 runs for without changes, then ran 5 runs for with changes. Between each run I copied the new results to a text file editor. No other major applications were running in the background. After multiple runs I still believe the run times for both with and without changes are very similar, with slight increases for with changes in runs 2 and 4. Edit: Replaced copied results with an .xlsx file that does a better job of succinctly displaying results. Thank you @harishsk for the heads up. |
Fixes #4914
WeakReference objects are stored in
_children
. Occasionally Garbage Collector cleans up these WeakReferences and change theirtarget
value to null, but theirWeakReference
s in theList _children
are never removed. This PR explicity removed thoseWeakReference
objects that have null targets.List.RemoveAll()
has a time-complexity of O(n) where n is the number of objects inList
.