You’re getting somewhere. Now the
Xc, Xd fields are still untyped; can you fix that?
Your mean alloc size is now ~40 bytes. That is exactly the size of a standard view. If this is correct, i.e. you mostly have views, then you need to think about getting rid of them.
If you determine that they impact performance, then you need to figure out which views are allocating (using
julia --track-allocation) and do one of two things: Either add some
@inline if possible, or remove the views by writing explicit loops instead of broadcasts.
Views only exist in order to permit people to be lazy about writing an API that uses
AbstractVector. If you control the function you pass the view to, then you can change the API: For example, turn
function some_fun(v::AbstractVector) into
function some_fun(M::AbstractMatrix, row_id) and call it by
some_fun(M, i) instead of
some_fun(view(M, :, i)).
This is somewhat ugly. I think it is not recommended to crank out shitty APIs in order to work around the compiler / gc limitation that views sometimes allocate. Sometimes it is necessary, though. Afaict this limitation will stay with us for a while (when I last whined about it, I was told that this is due to lack of resources, different priorities, and carnaval stopping to work on it).
You can of course consider using unsafe views (pointer based); then you need to handle some memory management by hand.