airlift / slice

Java library for efficiently working with heap and off-heap memory
Apache License 2.0
505 stars 129 forks source link

Implement SizeOf for Optional, Set and primitive wrappers #144

Closed arhimondr closed 2 years ago

arhimondr commented 2 years ago

The "empty" object is a static constant. While the object still uses space given the context in what the sizeof method is most often used (calculating retained size) it feels like it's practical to return 0. What do you think?

On Mon, Dec 6, 2021, 9:18 PM Martin Traverso @.***> wrote:

@.**** commented on this pull request.

In src/main/java/io/airlift/slice/SizeOf.java https://github.com/airlift/slice/pull/144#discussion_r763576356:

@@ -97,6 +105,26 @@ public static long sizeOf(Object[] array) return (array == null) ? 0 : sizeOfObjectArray(array.length); }

  • public static long sizeOf(Optional optional, ToLongFunction valueSize)
  • {
  • return optional.isPresent() ? OPTIONAL_INSTANCE_SIZE + valueSize.applyAsLong(optional.get()) : 0;
  • }
  • public static long sizeOf(OptionalInt optional)
  • {
  • return optional.isPresent() ? OPTIONAL_INT_INSTANCE_SIZE : 0;

Why 0 if it's absent? Objects of type OptionalInt still occupy space in that case.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/airlift/slice/pull/144#pullrequestreview-824704345, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKQDLCOBXS5AYTCEN4PRIDUPVVITANCNFSM5JP3PCTA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

arhimondr commented 2 years ago

Added an implementation for Set

arhimondr commented 2 years ago

Added implementations for primitive wrappers