Skip to content
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

Performance: consider Dictionaries.jl #99

Open
Datseris opened this issue Dec 10, 2019 · 5 comments
Open

Performance: consider Dictionaries.jl #99

Datseris opened this issue Dec 10, 2019 · 5 comments

Comments

@Datseris
Copy link
Member

Following the recent announcement : https://discourse.julialang.org/t/ann-dictionaries-jl-improved-productivity-and-performance-of-dictionaries-in-julia/32074

it seems to me that this is something relevant, as the central structure of Agents.jl is a dictionary. I think we should definitely benchmark a model with using the standard Julia version or this version.

@kavir1698
Copy link
Collaborator

There seems to be no advantage in using Dictionaries.jl, if not regression. Updated code is on branch dictionaries.jl.

Benchmarks on master:

Forest fire model
BenchmarkTools.Trial: 
  memory estimate:  1.71 MiB
  allocs estimate:  18178
  --------------
  minimum time:     4.695 ms (0.00% GC)
  median time:      4.942 ms (0.00% GC)
  mean time:        5.129 ms (2.04% GC)
  maximum time:     9.060 ms (32.80% GC)
  --------------
  samples:          742
  evals/sample:     1

move_agent!
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     59.909 ns (0.00% GC)
  median time:      61.944 ns (0.00% GC)
  mean time:        63.478 ns (0.00% GC)
  maximum time:     90.292 ns (0.00% GC)
  --------------
  samples:          229
  evals/sample:     981

id2agent
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     8.415 ns (0.00% GC)
  median time:      8.585 ns (0.00% GC)
  mean time:        8.812 ns (0.00% GC)
  maximum time:     25.422 ns (0.00% GC)
  --------------
  samples:          230
  evals/sample:     999

kill_agent!
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     351.000 ns (0.00% GC)
  median time:      550.000 ns (0.00% GC)
  mean time:        699.616 ns (0.00% GC)
  maximum time:     2.475 μs (0.00% GC)
  --------------
  samples:          232
  evals/sample:     1

Schelling model
BenchmarkTools.Trial: 
  memory estimate:  4.93 MiB
  allocs estimate:  106119
  --------------
  minimum time:     11.718 ms (0.00% GC)
  median time:      12.231 ms (0.00% GC)
  mean time:        12.729 ms (3.60% GC)
  maximum time:     17.035 ms (22.44% GC)
  --------------
  samples:          322
  evals/sample:     1

Using Dictionaries:

Forest fire model
BenchmarkTools.Trial: 
  memory estimate:  1.71 MiB
  allocs estimate:  17977
  --------------
  minimum time:     4.848 ms (0.00% GC)
  median time:      5.020 ms (0.00% GC)
  mean time:        5.152 ms (2.05% GC)
  maximum time:     8.484 ms (35.08% GC)
  --------------
  samples:          744
  evals/sample:     1

move_agent!
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     61.499 ns (0.00% GC)
  median time:      64.213 ns (0.00% GC)
  mean time:        67.199 ns (0.00% GC)
  maximum time:     103.622 ns (0.00% GC)
  --------------
  samples:          224
  evals/sample:     979

id2agent
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     10.317 ns (0.00% GC)
  median time:      10.410 ns (0.00% GC)
  mean time:        10.932 ns (0.00% GC)
  maximum time:     26.890 ns (0.00% GC)
  --------------
  samples:          228
  evals/sample:     999

kill_agent!
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     415.000 ns (0.00% GC)
  median time:      715.000 ns (0.00% GC)
  mean time:        949.429 ns (0.00% GC)
  maximum time:     2.827 μs (0.00% GC)
  --------------
  samples:          224
  evals/sample:     1

Schelling model
BenchmarkTools.Trial: 
  memory estimate:  4.53 MiB
  allocs estimate:  93606
  --------------
  minimum time:     11.126 ms (0.00% GC)
  median time:      11.646 ms (0.00% GC)
  mean time:        12.058 ms (3.19% GC)
  maximum time:     16.203 ms (21.62% GC)
  --------------
  samples:          336
  evals/sample:     1

@Datseris
Copy link
Member Author

Thanks a lot for checking this. Okay, in hindsight it makes a bit of a sense. Dictionaries.jl have been heavily optimized for doing operations across the values of the dictionary, which preserve the hash table. E.g. adding some number to all values. We don't really do this kind of stuff here, and in fact never create more than one dictionary (besides the replicates/parallel thing).

@Datseris Datseris reopened this Jun 10, 2020
@Datseris
Copy link
Member Author

I am reopening this because someone brought this PR into my attention : andyferris/Dictionaries.jl#13 which will supposedly make Dictionaries.jl much faster than what it was. I think once this happens we should try once more.

@Libbum
Copy link
Member

Libbum commented Jun 11, 2020

Side note if I'm reading that PR correctly. If we implement this here, we'll need to consider our schedulers. Since insertion will be order preserving for these dictionaries, fastest will thus be in most cases equivalent to by_id.

@Libbum
Copy link
Member

Libbum commented Jul 14, 2020

This PR has been merged, so we can dig this issue up again and begin testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants