I have a function which I need to make as efficient as possible.
The function takes many many inputs, and I have organised them into a structure in order to make the code more manageble and clean.
I have noticed that some times when within the function I modify the content of the structure pass to the function then some memory allocation happens, which slows down the code.
Here is a working example. Is there a way to avoid allocation while keep using a structure, or something similar, to group the inputs?
using BenchmarkTools mutable struct My_struct vector_1::AbstractVector end function my_function!(input::My_struct) input.vector_1 = 1 + input.vector_1 # allocations occur here, I guess to manage the right hand side return nothing end # test structure_1 = My_struct(ones(10)) @btime my_function!(structure_1)
63.500 ns (2 allocations: 32 bytes)