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

Use a mutable struct for the state of GridSpaceIdIterator #936

Merged
merged 3 commits into from
Nov 18, 2023

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Nov 18, 2023

This reduces the allocations of the iterator.

As you can see on this Flocking benchmark inside the ABMFrameworkComparison repo the speed improvement is nice:

#before
julia> a = @benchmark run_model(rng, (150, 150), 400, 15.0) setup = (rng = rng_model()) evals=1 samples=n_run seconds=1e6
BenchmarkTools.Trial: 100 samples with 1 evaluation.
 Range (min  max):  37.952 ms  61.669 ms  ┊ GC (min  max): 5.92%  8.08%
 Time  (median):     47.160 ms              ┊ GC (median):    7.55%
 Time  (mean ± σ):   47.599 ms ±  4.318 ms  ┊ GC (mean ± σ):  7.46% ± 1.12%

                ▆   ▂▆  █▄ █  ▄ ▂                              
  ▄▄▁▁▄▁▁▁█▁▆▆▄██▆█▆██▆▄██▆█▆██▄██▄▆█▄▆▁▆▁▁▆█▁▄▁▆▁▁▁▁▁▁▁▁▁▁▁▄ ▄
  38 ms           Histogram: frequency by time          61 ms <

 Memory estimate: 98.61 MiB, allocs estimate: 2151950.

#after
julia> a = @benchmark run_model(rng, (150, 150), 400, 15.0) setup = (rng = rng_model()) evals=1 samples=n_run seconds=1e6
BenchmarkTools.Trial: 100 samples with 1 evaluation.
 Range (min  max):  32.827 ms  52.396 ms  ┊ GC (min  max): 3.73%  2.89%
 Time  (median):     40.189 ms              ┊ GC (median):    6.13%
 Time  (mean ± σ):   40.487 ms ±  3.500 ms  ┊ GC (mean ± σ):  6.12% ± 1.13%

                   █   ▄▆▁▆   ▁                                
  ▄▄▄▄▁▄▁▄▄▄▁▆▇▇▆▇▆█▇▇▇████▆▇▇█▆▆▄▆▄▇▁▄▇▄▆▄▄▁▄▁▁▁▄▁▁▁▁▁▁▁▁▁▁▄ ▄
  32.8 ms         Histogram: frequency by time          52 ms <

 Memory estimate: 67.06 MiB, allocs estimate: 2191950.

(using Ref.(....) to retrieve the fields can sometimes have a bad effect on inference, so I also changed that)

@Tortar Tortar requested a review from Datseris November 18, 2023 12:44
@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (de82efd) 80.74% compared to head (1d722c2) 92.27%.

❗ Current head 1d722c2 differs from pull request most recent head 4a4aae4. Consider uploading reports for the commit 4a4aae4 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #936       +/-   ##
===========================================
+ Coverage   80.74%   92.27%   +11.52%     
===========================================
  Files          45       33       -12     
  Lines        2955     2277      -678     
===========================================
- Hits         2386     2101      -285     
+ Misses        569      176      -393     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's nice! Do we have a changelog entry for performance increases? we shyuld write this there!

@Tortar
Copy link
Member Author

Tortar commented Nov 18, 2023

made one 👍

@Tortar Tortar merged commit 37d3a13 into main Nov 18, 2023
5 checks passed
@Tortar Tortar deleted the faster-nearby-ids branch November 18, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants