-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add_agent!(model, properties...)
much slower than add_agent!(agent, model)
with random position
#820
Comments
wow this is tough. From a first glance, the solution is not at all obvious to me... |
So the second method uses the following code and then calls the first method: Agents.jl/src/core/space_interaction_API.jl Lines 257 to 285 in 14886a4
|
Actually now I can reproduce with this "simpler" version the same behaviour in 1.8.3: using BenchmarkTools
mutable struct A
q_0::Int
q_1::Int
q_2::Int
end
@noinline function g_1()
for n in 1:1000
a = A(rand(1:2), 1, 1)
f(a)
end
end
@noinline function g_2()
for n in 1:1000
f(A, 1, 1)
end
end
@noinline function f(a::A)
return a
end
@noinline function f(a::Type{A}, properties...)
return a(rand(1:2), properties...)
end
@benchmark g_1()
@benchmark g_2() but I have still no idea why this happens, the only thing I managed to find out is that if I put |
This seems somewhat related: https://discourse.julialang.org/t/splatting-arguments-causes-30x-slow-down/16964 |
Strangely enough these two ways of adding agents haven't the same performance:
the difference is very big:
Still more strangely using instead e.g.
add_agent!((1,1), model, 1, 1, 1, 1)
has better performance than the first way. I tried to investigate why this happens and didn't find the cause of all of thisThe text was updated successfully, but these errors were encountered: