I have noticed that a particular calculation in the
MixedModels package unexpectedly allocates a lot of storage. The method in question is around lines 340 to 350 of
modelterms.jl. The calculation involves the columns of a
n matrix where
k << n and a
PooledDataArray which indicates which group the column is part of. There are
g groups. In the code, the
A.f.refs will contain the integers
g < n.
The output value is a
k matrices called
d in the code. These are zeroed out then each column is used in a rank-1 update of the corresponding element of
d. Right now the loop is written
for i in eachindex(refs) ## FIXME: A lot of allocation going on here BLAS.syr!('L', one(T), view(Az, :, i), d[refs[i]]) end
Checking with --track-allocation shows considerable allocation in this loop (which is called many times on a large problem).
0 for i in eachindex(refs) - ## FIXME: A lot of allocation going on here 1690606080 BLAS.syr!('L', one(T), view(Az, :, i), d[refs[i]]) - end
I don’t understand where the allocation is coming from. I had thought that a view would be lightweight, especially a view of a column in a matrix.
Is there a better way of writing this so as to avoid all the allocation?