Remove malloc/free#588
Conversation
|
Thanks! I think this would be a performance improvement for small N orbits that require transformation, but won't this then risk causing stack overflows for direct |
|
Adding @lgarrison to see if he has any opinions here too :). |
|
Yeah, I think there's a risk of a stack overflow here. Could we instead allocate scratch space on the heap higher in the call chain (outside of the hot loop) and pass that down to |
|
Yes, I can see that if N is in the millions, it could be an issue. |
|
I asked Claude to implement the idea of allocating scratch space at a higher level. The results weren't encouraging, the change surface is pretty big: So what about this instead: we could allocate Any thoughts on this? |
|
Thanks @lgarrison for doing that experiment! I think your thread local scratch space idea would be fine and covers most practical use cases. |
Describe your changes
The coordinate transformation code in c_gradient does malloc/free at each call, which shows up in CPU profiles when running orbits/streams. I don't think there is a need for memory allocation, when stack arrays would work.
Checklist
CHANGES.rst) No (not sure it's worth an entry or not)