Feature Request: Memory allocation only when necessary
Submitted by Piotr Trebisz
Assigned to Nobody
I'm Piotr Trebisz from the GFaI e.V. institute in Berlin. I work as a software developer in the 3D-Data-Processing departement of the institute. We decided to use "Eigen" because we are tired of spending time on writing our own numerical methods and Eigen seems to yield good results in terms of accuracy.
But we also identified a little performance issue: Eigen frees and allocates memory on every matrix resize, on every computation of a matrix decomposition and on every other change of an objects size, and that costs some time. If you only want to solve 1 or just a few equation systems, then it's not a problem. But our programms often have to solve some 100.000 to some 1.000.000 equation systems whose dimensions vary from iteration step to iteration step.
Freeing and allocating bigger matrices, vectors and matrix-decomposition-objects 100.000 to 1.000.000 times has a negative impact on performance. Therefore in our departement and in many other scientific institutions it is regarded as best practice in numerical algorithms to allocate new memory only when the old memory is not big enough. When an object shrinks, the memory is keept and not freed. Our objects have an extra method called "FreeExtra" if one explicitly wants to free unused memory.
With Eigen's map-templates it is possible to manage the memory of matrices and vectors by our own. But it is not possible to do so with all the other objects like JacobiSVD- and HouseholderQR-Decompositions. Therefore we would like to know if you could think about our suggestion and consider such a memory management for future Eigen releases.