In RigidBodyDynamics.jl, I was able to reduce allocations to zero in a few of the key algorithms. This took quite some effort, mostly because I started out just getting things to work without paying a lot of attention to allocation, after which it was not easy to find exactly what code was allocating. I suppose this is in part due to the fact that track-allocation={user,all}
does not report line numbers accurately (e.g. https://github.com/JuliaLang/julia/issues/11753, https://github.com/JuliaLang/julia/issues/19502), especially in inlined code with 0.5.
Issues with track-allocation
aside, it would have been very useful for me if there were a way to tell Julia to just throw an error whenever a dynamic allocation is about to be performed. That way you would just directly get a stack trace instead of having to dig through .mem
files. The Eigen C++ library has an EIGEN_RUNTIME_NO_MALLOC
preprocessor directive and a set_is_malloc_allowed(bool)
function that implement this kind of functionality (bottom of page). Of course, Eigen has a much narrower scope than Julia. But if this kind of thing is at all feasible in Julia, I think it would be incredibly useful. Any thoughts on this?