JuliaDynamics / ABMFrameworksComparison

Benchmarks and comparisons of leading ABM frameworks
Other
13 stars 8 forks source link

suboptimal allocation of trees on fire in Agents.jl ForestFire implementation #61

Closed Datseris closed 1 year ago

Datseris commented 1 year ago

This line does not appear optimal to me:

https://github.com/JuliaDynamics/ABM_Framework_Comparisons/blob/main/ForestFire/Agents/ForestFire.jl#L17

findall(isequal(2), forest.trees) allocates a vector with the burning trees. To do that, it anyways iterates over all trees.

Wouldn't it faster to explicitly iterate ourselves and skip non burning trees? I.e., do

@inbounds for I in eachindex(forest.trees)
forest.trees[I] != 2 && continue
# remaining code is identical
Tortar commented 1 year ago

No it doesn't since probably findall is more optimized than a simple loop (I see a 2x slowdown with iteration).

However changing trees = zeros(Int, griddims),) in trees = zeros(Int8, griddims),) helps a bit (15% faster, not much) in terms of performance

Tortar commented 1 year ago

Actually somewhat better than expected, forestfire-large in respect to Mesa passed from 494x to 645x