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

Inefficient Usages of Java Collections #8784

Merged
merged 14 commits into from
Sep 14, 2021
Merged

Inefficient Usages of Java Collections #8784

merged 14 commits into from
Sep 14, 2021

Conversation

FastAtlas
Copy link
Contributor

Hi,

We find that there are several inefficient usages of Java Collections:

  1. The contains method is invoked upon a list object in a loop. We recommend replacing it with a HashSet.
  2. Random access can occur at several LinkedList objects, which run in linear time complexity. We recommend replacing them with Arraylist objects.
  3. There is no iteration occurring upon a LinkedHashMap and LinkedHashSet, thus the insertion order does not matter. We recommend replacing it with a HashMap and HashSet.
  4. ArrayList is inserted before an iteration, while multiple memory reallocation might occur when the size of the list exceeds its capacity. We recommend replacing it with a LinkedList.

We discovered the above inefficient usage of containers by our tool Ditto. The patch is submitted. Could you please check and accept it? We have tested the patch on our PC. The patched program works well.

Bests

Ditto

@mercyblitz
Copy link
Contributor

Please fix the checkstyle issue first, thanks.

@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2021

Codecov Report

Merging #8784 (2bb3ba8) into 3.0 (5c2161a) will decrease coverage by 0.00%.
The diff coverage is 52.94%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.0    #8784      +/-   ##
============================================
- Coverage     63.92%   63.92%   -0.01%     
+ Complexity      315      314       -1     
============================================
  Files          1156     1156              
  Lines         48702    48703       +1     
  Branches       7324     7324              
============================================
  Hits          31134    31134              
- Misses        14175    14177       +2     
+ Partials       3393     3392       -1     
Impacted Files Coverage Δ
...figcenter/file/FileSystemDynamicConfiguration.java 0.00% <0.00%> (ø)
.../apache/dubbo/config/bootstrap/DubboBootstrap.java 53.40% <ø> (ø)
...n/serialize/support/SerializableClassRegistry.java 0.00% <0.00%> (ø)
...ate/endpoint/metadata/DubboReferencesMetadata.java 5.55% <0.00%> (ø)
...factory/config/ServiceBeanIdConflictProcessor.java 0.00% <0.00%> (ø)
...apache/dubbo/common/extension/ExtensionLoader.java 81.71% <71.42%> (+0.23%) ⬆️
...c/cluster/router/mesh/rule/VsDestinationGroup.java 100.00% <100.00%> (ø)
.../java/org/apache/dubbo/common/utils/TypeUtils.java 70.27% <100.00%> (ø)
...main/java/org/apache/dubbo/qos/textui/TLadder.java 100.00% <100.00%> (ø)
...ng/transport/dispatcher/all/AllChannelHandler.java 89.65% <0.00%> (-6.90%) ⬇️
... and 12 more

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 5c2161a...2bb3ba8. Read the comment docs.

@mercyblitz mercyblitz merged commit 914c377 into apache:3.0 Sep 14, 2021
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.

3 participants