1
0

[HUDI-3652] Make ObjectSizeCalculator threadlocal to reduce memory footprint (#5060)

Co-authored-by: zhouhuidong <zhouhuidong@bilibili.co>
This commit is contained in:
sekaiga
2022-04-14 18:08:14 +08:00
committed by GitHub
parent 6621f3cdbb
commit f0ab4a6e9e

View File

@@ -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.