A recent thread on the Julia users’ newsgroup about SparseMatrixCSC made me realize that my code may have a hidden inefficiency. My code has the following structure. A key computational routine is GAssemble, similar to finite element matrix assembly. It repeatedly invokes another function, say EAssemble, for individual element assembly. EAssemble uses dozens of small matrices/vectors of small fixed size (size fixed at run time, not compile time.) So I created a composite type called WorkSpace, and the initializer for a WorkSpace allocates all the dozens of small arrays and matrices. GAssemble invokes this initializer for the workspace once, and then it passes the workspace to EAssemble many times inside a loop.
Question: Should WorkSpace be an immutable composite (immutable
) or an ordinary composite (type
)?
Argument in favor of ordinary composite: the header information for all of the dozens of small matrices and vectors does not have to be copied over each time EAssemble is invoked.
Argument in favor of immutable composite: I just learned from the recent discussion that if typeof(ws)==WorkSpace, and Workspace is an ordinary (mutable) composite type, then a reference to a matrix element like ws.a[i,j] inside a tight loop needs multiple dereferencing at run-time because the compiler apparently can’t tell that ws.a didn’t change since the last loop iteration. (In which version of Julia??)
Suggestions would be appreciated!
– Steve Vavasis