Skip to content
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

Merged
merged 1 commit into from
Jan 28, 2019

Conversation

luoxn28
Copy link
Contributor

@luoxn28 luoxn28 commented Jan 27, 2019

Describe what this PR does / why we need it

  1. Init a new hash map size using old hash map size, avoid new hash map rehash when putAll operation .

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

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2019

CLA assistant check
All committers have signed the CLA.

@codecov-io
Copy link

codecov-io commented Jan 27, 2019

Codecov Report

Merging #465 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...tinel/slots/clusterbuilder/ClusterBuilderSlot.java 71.42% <100%> (ø) 8 <0> (ø) ⬇️
...a/csp/sentinel/slots/statistic/base/LeapArray.java 64.55% <0%> (-3.8%) 23% <0%> (-1%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30907e4...624e654. Read the comment docs.

@@ -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));

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.

@sczyh30 sczyh30 added the to-review To review label Jan 28, 2019
@sczyh30
Copy link
Member

sczyh30 commented Jan 28, 2019

Hi, could you please sign the CLA here: https://cla-assistant.io/alibaba/Sentinel?pullRequest=465

@sczyh30 sczyh30 changed the title hash map init optimize HashMap init optimize when adding new ClusterNode to cluster node map Jan 28, 2019
@sczyh30 sczyh30 merged commit f306a03 into alibaba:master Jan 28, 2019
@sczyh30
Copy link
Member

sczyh30 commented Jan 28, 2019

Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants