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

perf: Access grid only once #1751

Merged
merged 1 commit into from
Aug 3, 2023
Merged

perf: Access grid only once #1751

merged 1 commit into from
Aug 3, 2023

Conversation

Corvince
Copy link
Contributor

@Corvince Corvince commented Aug 3, 2023

In our current implementation we access the grid first to check if the cell is empty and then a second time to iterate over the contents. Inlining the check and using the walrus operator allows to access the content only once.

Using the ABM framework comparison i get the following speedups on my laptop for the Schelling model.

Model main this PR
Schelling (small) 136ms 97ms
Schelling (large) 2120ms 1558ms

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (2cec830) 72.35% compared to head (7adf4ad) 72.35%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1751   +/-   ##
=======================================
  Coverage   72.35%   72.35%           
=======================================
  Files          20       20           
  Lines        1302     1302           
  Branches      246      246           
=======================================
  Hits          942      942           
  Misses        325      325           
  Partials       35       35           
Files Changed Coverage Δ
mesa/space.py 90.88% <ø> (ø)

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

@Corvince
Copy link
Contributor Author

Corvince commented Aug 3, 2023

On the Schelling performance I also opened JuliaDynamics/ABMFrameworksComparison#57 which could give us a 3-5x advantage

Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

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

This is very cool, thanks!

LGTM

@tpike3 tpike3 merged commit b53aa2f into main Aug 3, 2023
@rht rht deleted the perf-1 branch August 4, 2023 02:21
@tpike3 tpike3 added this to the Release 2.1.2 milestone Sep 19, 2023
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