Skip to content

Commit

Permalink
[HUDI-3652] use threadlocal to decrease ObjectSizeCalculator memory use
Browse files Browse the repository at this point in the history
[HUDI-3652] Make ObjectSizeCalculator threadlocal to reduce memory footprint
  • Loading branch information
zhouhuidong committed Mar 18, 2022
1 parent 91849c3 commit 0528eca
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
* @author Attila Szegedi
*/
public class ObjectSizeCalculator {
private static final ThreadLocal<ObjectSizeCalculator> objectSizeCalculator = ThreadLocal.withInitial(() -> new ObjectSizeCalculator(CurrentLayout.SPEC));

private static class CurrentLayout {

private static final MemoryLayoutSpecification SPEC = getEffectiveMemoryLayoutSpecification();
Expand All @@ -71,7 +73,7 @@ private static class CurrentLayout {
* @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 : objectSizeCalculator.get().calculateObjectSize(obj);
}

// Fixed object header size for arrays.
Expand Down

0 comments on commit 0528eca

Please sign in to comment.