Ah, I think I forgot about the “global” character of variables not interpolated.
But still: I am passing them into a function, where they will be happily local.
So, not much of a difference between A interpolated or not. So, why the huge difference for copyto!?
Edit: For larger vectors the difference between @btime copyto!(U1, U0) and @btime copyto!($U1, $U0) disappears. Still: why is there a difference for small vectors?
Recall that the loop refers to the variable dt.
The trigger is this: If I compute omega_max from the solution of an eigenvalue problem, the loop would allocate.
So I know you’ve found this thread to be a red-herring on your way to the more complicated issue you’re trying to debug, but there is a pretty straightforward answer to how BenchmarkTools uses that $ syntax. It simply constructs its benchmarking loop such that anything that’s $'ed is an argument to the function. Everything else is considered a global. How big of an effect this has is entirely dependent upon what Julia is doing.
In general, you want to make sure all function-local variables in your original example have $'s on them in their benchmarks.
The arguments are globals. The compiler knows they are globals. It has no way of knowing whether those globals are mutated inside copyto! or some ancillary function. Therefore each time it calls copyto! in the benchmark loop it must check the type of the global inputs and dispatch dynamically.
Interpolating tells the compiler the value of the input, rather than the global variable that points to that value.