This is an automated email from the ASF dual-hosted git repository.

xushiyan pushed a commit to branch 
cherrypick-f0ab4a6e9ef433ac943d2409051418f7f80a6902
in repository https://gitbox.apache.org/repos/asf/hudi.git

commit 4a5d6a39b2a28a7b72056a4280202a0d97e1445f
Author: sekaiga <[email protected]>
AuthorDate: Thu Apr 14 18:08:14 2022 +0800

    [HUDI-3652] Make ObjectSizeCalculator threadlocal to reduce memory 
footprint (#5060)
    
    Co-authored-by: zhouhuidong <[email protected]>
---
 .../main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java
 
b/hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java
index 7e625e8eb4..99b2d5a2cb 100644
--- 
a/hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java
+++ 
b/hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java
@@ -54,6 +54,8 @@ import java.util.Set;
  * @author Attila Szegedi
  */
 public class ObjectSizeCalculator {
+  private static final ThreadLocal<ObjectSizeCalculator> 
OBJECT_SIZE_CALCULATOR_THREAD_LOCAL = ThreadLocal.withInitial(() -> new 
ObjectSizeCalculator(CurrentLayout.SPEC));
+
   private static class CurrentLayout {
 
     private static final MemoryLayoutSpecification SPEC = 
getEffectiveMemoryLayoutSpecification();
@@ -71,7 +73,7 @@ public class ObjectSizeCalculator {
    * @throws UnsupportedOperationException if the current vm memory layout 
cannot be detected.
    */
   public static long getObjectSize(Object obj) throws 
UnsupportedOperationException {
-    return obj == null ? 0 : new 
ObjectSizeCalculator(CurrentLayout.SPEC).calculateObjectSize(obj);
+    return obj == null ? 0 : 
OBJECT_SIZE_CALCULATOR_THREAD_LOCAL.get().calculateObjectSize(obj);
   }
 
   // Fixed object header size for arrays.

Reply via email to