Union{} slots are not 0 bits, they are currently managed pointers #34244
Labels
compiler:codegen
Generation of LLVM IR and native code
domain:types and dispatch
Types, subtyping and method dispatch
performance
Must go faster
This issue is possibly a subset of some other issues involving
Union
s ofisbits
types (things like #29289) but I suspect it is easier to satisfy with a special case forUnion{}
rather than a full generic solution for all possibleUnion
types.It is becoming more frequent to use the
Union{}
type as slots of (immutable)struct
s andArray
s, especially as we move away from containers constructed witheltype
coming fromCore.Compiler.return_type
and while also correctly dealing with empty containers (or starting an algorithm with an empty container and filling elements).Unfortunately, this represents a bit of a performance problem in certain cases. On my 64-bit intel system, I get 8 bytes allocated per
Union{}
slot, presumably filled with null pointers that can never be set. Cases where this can be particularly important include creation ofSVector
s andDataValue
s - in the latter case theNA
type is, unfortunately, not singleton likemissing
. In both those examples we are often aiming for allocation-free algorithms for speed, friendliness for GPUs, etc. Another case is when experimenting with removing all usage ofreturn_type
fromcollect
ormap
or whatever, starting with aneltype
ofUnion{}
with zero filled elements and adding elements and widening theeltype
from there - which means in the simple case of perfect inference of a simple bits type you get an extra allocated array.Some minimal examples.
I would hope for
0
,true
and0
respectively.The text was updated successfully, but these errors were encountered: