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

Improve performance of EventQueueABM by better union splitting #1065

Merged
merged 4 commits into from
Aug 11, 2024

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Aug 10, 2024

before

julia> model = initialize_rps();

julia> @benchmark step!($model)
BenchmarkTools.Trial: 10000 samples with 197 evaluations.
 Range (min  max):  426.081 ns   56.132 μs  ┊ GC (min  max): 0.00%  98.59%
 Time  (median):     471.038 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   512.019 ns ± 745.854 ns  ┊ GC (mean ± σ):  5.40% ±  4.60%

         ▂▄▆▇█▇▆▄▃▁                                              
  ▁▁▂▃▄▅████████████▆▅▃▃▃▂▂▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁ ▃
  426 ns           Histogram: frequency by time          641 ns <

 Memory estimate: 378 bytes, allocs estimate: 7.

after

julia> model = initialize_rps();

julia> @benchmark step!($model)
BenchmarkTools.Trial: 10000 samples with 207 evaluations.
 Range (min  max):  343.237 ns   46.423 μs  ┊ GC (min  max): 0.00%  98.19%
 Time  (median):     390.423 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   409.583 ns ± 565.531 ns  ┊ GC (mean ± σ):  3.01% ±  2.53%

              ▂▃▅████▇▅▄▂▁                                       
  ▁▁▁▁▁▂▂▃▄▅▇█████████████▇▆▅▅▄▄▄▃▃▄▄▄▃▃▃▃▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁ ▃
  343 ns           Histogram: frequency by time          495 ns <

 Memory estimate: 157 bytes, allocs estimate: 2.

@Datseris
Copy link
Member

Datseris commented Aug 10, 2024

that's big!

can you give more info here? What are you doing? What is "union splitting" in this context? Why do we need to make the events a sized vector instead of a tuple?

@Tortar
Copy link
Member Author

Tortar commented Aug 10, 2024

The key idea here in my opinion is understanding that tuples are not made for this task (at least currently) because when the access to a tuple is random and there are multiple types inside it, the tuple will not union split but just use a dynamic dispatch mechanism. When the access is fixed a tuple would be instead be better. A SizedVector is instead a good one because as a Vector it will union-split, at the same time we know the size of it, so we can use a fixed-size one.

@Datseris
Copy link
Member

What does "union-split" mean?

@Datseris Datseris merged commit 50f5dcc into main Aug 11, 2024
6 checks passed
@Datseris Datseris deleted the Tortar-patch-2 branch August 11, 2024 08:46
@Tortar
Copy link
Member Author

Tortar commented Aug 11, 2024

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.

2 participants