Description
@dpsanders and I were wondering if there is a utility that works similar to @code_typed
and friends but works on struct definitions, rather than on methods. We wanted to know how a certain struct will end up represented in memory, in order to improve performance, but it's currently very hard to tell.
One example use case:
For instance, when a struct contains a field x::Union{Nothing,T}
, we want to know what kind of struct layout gets generated. Our understanding is that for types where T
will be heap-allocated, meaning x
will be a pointer, julia can treat the ::Nothing
case as essentially a null-pointer check, so it adds 0 space overhead. Whereas for types T
that are inline-allocated/stack-allocated, this requires an extra bit somewhere to track whether x
should be treated as the nothing case or the T
case. (like a tagged union.)
But it would be great to be able to confirm that understanding by running something like @struct_layout S
or @struct_llvm S
or something like that!