Class InstanceSizeEstimator


  • public class InstanceSizeEstimator
    extends java.lang.Object
    This utility class provides functions to measure the heap size of objects for a limited number of classes. Wherever possible, the logic makes use of knowledge of the Venice code so that shared or static instances are ignored (i.e., assuming that their amortized cost is negligible). The code here should all be hot path friendly, and make no use of reflection (except in static constants). If more classes require heap size measurement, the preferred approach is NOT to add code into this class! Rather, the preferred approach is to implement Measurable and write the logic in Measurable.getHeapSize(). This utility class is for cases where we wish to measure classes that we cannot modify, such as those coming from the JDK, from third-party libraries, or from code-gen.
    • Method Detail

      • getObjectSize

        public static int getObjectSize​(@Nonnull
                                        java.lang.Object o)
        Works for Measurable objects and a small number of other types. Not intended as a generic utility for any instance type!
        Throws:
        java.lang.IllegalArgumentException - when an unsupported type is passed.
      • getByteArraySizeByLength

        public static int getByteArraySizeByLength​(int length)
      • getSize

        public static int getSize​(@Nonnull
                                  byte[] bytes)
      • getSize

        public static int getSize​(java.nio.ByteBuffer byteBuffer)
      • getSize

        public static int getSize​(@Nonnull
                                  ProducerMetadata producerMetadata)
      • getSize

        public static int getSize​(@Nonnull
                                  Put put)
      • getSize

        public static int getSize​(@Nonnull
                                  Delete delete)
      • getSize

        public static int getSize​(@Nonnull
                                  ControlMessage cm)
        This function is imprecise in a couple of ways. The ControlMessage.controlMessageUnion field is treated as shallow, which in some cases is false (e.g. if a compression dictionary were present), and the ControlMessage.debugInfo is ignored (i.e. treated as null). We can be more precise by looking at the ControlMessage.controlMessageType and then providing the precise overhead based on each type, but we're skipping this work for now since, in our use case, control messages should be a negligible fraction of all messages, and therefore not that important to get exactly right.
      • getSize

        public static int getSize​(@Nonnull
                                  Update update)