You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/07/26 01:05:13 UTC

[GitHub] [bookkeeper] zymap commented on a diff in pull request #3417: Optimize concurrent collection's shrink logic

zymap commented on code in PR #3417:
URL: https://github.com/apache/bookkeeper/pull/3417#discussion_r929436578


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java:
##########
@@ -507,7 +507,11 @@ private V remove(long key, Object value, int keyHash) {
             } finally {
                 if (autoShrink && size < resizeThresholdBelow) {
                     try {
-                        int newCapacity = alignToPowerOfTwo((int) (capacity / shrinkFactor));
+                        // Shrinking must at least ensure initCapacity,
+                        // so as to avoid frequent shrinking and expansion near initCapacity,
+                        // frequent shrinking and expansion,
+                        // additionally opened arrays will consume more memory and affect GC
+                        int newCapacity = Math.max(alignToPowerOfTwo((int) (capacity / shrinkFactor)), initCapacity);

Review Comment:
   Why not just skip shrink when the size is smaller than the alignToPowerOfTwo(initCapacity)? That would save a lot of computing of `alignToPowerOfTwo((int) (capacity / shrinkFactor))`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org