Structs with Fixed length strings and allocatedinline

I have struct like this,

struct A
        a:: Symbol
end

I see a huge number of allocations of objects Union{A, Nothing}. I checked

> Base.allocatedinline(A)
true
> Base.allocatedinline(Union{A, Nothing})
false

I originally wished it to be Symbol, because there are few of them possible and wanted equality to be faster.

I tried both InlinedStrings.jl and StaticStrings.jl libraries. Though the allocatedinline of the same with StaticString field (the union type) is true now, the equality has gone worse. My allocations have halved but it has slowed down tremendously. (InlinedStrings still says allocatedinline as false for the union type for some reason).

I am not sure how people generally avoid allocation of structs with string fields

For me it seems a bit like the concrete usage could make a difference. Do you create a lot of these structs all the time, are you processing large arrays with such data… A minimal example could help to get relevant answers.

(My initial guess is that you might deal with some vector where the type is not fixed and the allocations stem from runtime dispatch rather then actual allocations of Union{A, Nothing}.)


I think it is important to differentiate between necessary allocations and allocations which cause a slow-down. Say, if you have one million strings of length 10, then it might be good to allocation one million strings in as few calls as possible, maybe even in a smart way. However, it would not make sense to do all of that in the heap or inline, as it is too much data.

That is why the use case could matter.