-
Notifications
You must be signed in to change notification settings - Fork 8k
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
HashMap init optimize when adding new ClusterNode to cluster node map #465
Conversation
Codecov Report
@@ Coverage Diff @@
## master #465 +/- ##
============================================
- Coverage 37.66% 37.62% -0.05%
+ Complexity 983 982 -1
============================================
Files 235 235
Lines 7429 7429
Branches 1017 1017
============================================
- Hits 2798 2795 -3
- Misses 4271 4273 +2
- Partials 360 361 +1
Continue to review full report at Codecov.
|
@@ -81,7 +81,7 @@ public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode | |||
if (clusterNode == null) { | |||
// Create the cluster node. | |||
clusterNode = Env.nodeBuilder.buildClusterNode(); | |||
HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<ResourceWrapper, ClusterNode>(16); | |||
HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<ResourceWrapper, ClusterNode>(Math.max(clusterNodeMap.size(), 16)); |
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.
First, we can use type inference instead of explicit type parameter here:
new HashMap<>(...);
Second, the initial size should be the max of (int) clusterNodeMap.size() / 0.75 + 1
and 16.
Hi, could you please sign the CLA here: https://cla-assistant.io/alibaba/Sentinel?pullRequest=465 |
Thanks for contributing! |
Describe what this PR does / why we need it
Does this pull request fix one issue?
NONE
Describe how you did it
use old hash map size init new hash map size.
Describe how to verify it
checked
Special notes for reviews