-
Notifications
You must be signed in to change notification settings - Fork 12.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
refactor: isChangedServiceInfo method in ServiceInfoHolder has been r… #10882
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #10882 +/- ##
=============================================
- Coverage 53.29% 53.27% -0.03%
- Complexity 5621 5625 +4
=============================================
Files 927 927
Lines 29555 29538 -17
Branches 3249 3246 -3
=============================================
- Hits 15751 15735 -16
- Misses 12420 12434 +14
+ Partials 1384 1369 -15
... and 24 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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 think the change will lead to increased time complexity.
The old implementation: loop newHosts and oldHosts twice for each.
But new implementation loop newHosts and oldHosts third times(host to map, map key set merge, and merged key set loop).
Why not do enhance directly in this issue? The situation prefer performance I think. And the old one I think the readability has no much different for new implementaton. |
@KomachiSion I have reworked the code again, this time removing the step where I converted newService.getHosts() into a map. Within the loop iterating over newService.getHosts(), I've completed the comparison tasks for Instance objects: if oldHost != null && oldHost == newHost if oldHost != null && newHost != oldHost if oldHost == null After filtering oldHostMap within the loop, at the end of the iteration, only data where newHost == null and oldHosts != null remain in oldHostMap. These data are directly placed in the remvHosts. Through this approach, there is no need to pre-convert newHosts into a map. Furthermore, it also reduces the requirement for two separate comparison and filtering loops. |
The isChangedServiceInfo method primarily aims to compare instance information for any changes and then categorize them into three separate collections: new, deleted, and modified collections.
In the original code, adding and modifying instances were processed within one loop, while deleting instances were handled in another loop, resulting in unnecessary iterations. In the refactored code, I combined the keys of the newHostMap and oldHostMap collections and used a HashSet to remove duplicates. Then, within the loop of the allHostMapKeys collection, the following conditions were checked sequentially:
newInstance != oldInstance
add modHosts
newInstance != null && oldInstance == null
add newHosts
newInstance == null && oldInstance != null
add remvHosts
Add them to the ArrayList, and there is no longer a need for HashSet to handle duplicate results,The improvement has enhanced the efficiency and code readability of the method, while also eliminating redundant processing.