some recommendation
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
I found such code in the the com.alibaba.csp.sentinel.node.DefaultNode#addChild(Node node) method: Set newSet = new HashSet<>(childList.size() + 1);
I don't think it's a approprite 'initialCapacity' for the hash set. Given childList.size()=6, then the initialCapacity is 7, and hash map would finally find the nearest number of a power of two, that is 8. So an add method would still trigger a resize method. Simply, we can refer to the HashMap#tableSizeFor method to calculate the real length of the underlining array and also we could calculate the threshold. Compare the childList.size with threshold to determine the length of array.
Contributor guide
Research direction
Start at com.alibaba.csp.sentinel.node.DefaultNode#addChild(Node node) and inspect how childList.size() is used to construct the HashSet. Compare that capacity with HashMap#tableSizeFor and the resulting threshold; done means the stated childList.size()=6 case avoids an unnecessary resize while preserving child insertion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100