Best practices for NonlinearSolve definition with temporary arrays

I would say that the best way to to get a “short” version of g would be to put all your temporary and fixed arrays into p. The easiest way to do this is probably by way of a NamedTuple, possibly a nested one. Thus, for example:

temp_arrays = (; temp_1 = temp_1, temp_2 = temp_2) # and so on
fixed_arrays = (; fixed_1 = fixed_1, fixed_2 = fixed_2) # and so on
param_values = (;a = 3.0, b = 7.5) # and so on
p = (; temp_arrays, fixed_arrays, param_values)

and then in your function

function g(u, p)
(; temp_arrays, fixed_arrays, param_values) = p
(;a, b) = param_values
(;temp_1, temp_2) = temp_arrays
(;fixed_1, fixed_2) = fixed_arrays
# [...]
return vals
end