Skip to content

util: Speed up combine by ~8x #233

Merged
quaquel merged 2 commits intoquaquel:masterfrom
EwoutH:performance-2
Apr 2, 2023
Merged

util: Speed up combine by ~8x #233
quaquel merged 2 commits intoquaquel:masterfrom
EwoutH:performance-2

Conversation

@EwoutH
Copy link
Copy Markdown
Collaborator

@EwoutH EwoutH commented Mar 23, 2023

Speed up the combine function by approximately 8x, by removing the intersect and deepcopy, and filling an new dictionary instead.

Benchmarks on the 25000 runs of the SIR_model:

  • old combine function: 1195ms (8.8% of runtime)
  • new combine function: 146ms (1.2% of runtime)

Note that this PR is stacked on top of #232. That one should be reviewed and merged first. For this PR only the changes in util.py are relevant.

@quaquel
Copy link
Copy Markdown
Owner

quaquel commented Mar 24, 2023

The code seems correct, but there is no unit test for the combine function. So, ideally, a test is written as well to ensure the behavior is indeed the same.

@EwoutH
Copy link
Copy Markdown
Collaborator Author

EwoutH commented Mar 24, 2023

Good point, I will do this after the weekend.

@EwoutH EwoutH force-pushed the performance-2 branch 3 times, most recently from 88ac54f to 586380e Compare March 28, 2023 07:52
@EwoutH
Copy link
Copy Markdown
Collaborator Author

EwoutH commented Mar 28, 2023

Added unittests, how do they look to you?

The tests pass both on the previous implementation and the one the new one.

Please review and if merging, please use fast-forward merge.

Copy link
Copy Markdown
Owner

@quaquel quaquel left a comment

Choose a reason for hiding this comment

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

looks good

EwoutH and others added 2 commits April 2, 2023 10:46
Speed up the combine function by approximately 8x, by removing the intersect and deepcopy, and filling an new dictionary instead.

Benchmarks on the 25000 runs of the SIR_model:
 - old combine function: 1195ms (8.8% of runtime)
 - new combine function: 146ms (1.2% of runtime)
@EwoutH
Copy link
Copy Markdown
Collaborator Author

EwoutH commented Apr 2, 2023

Thanks for the review!

I can't merge due to the required checks:

remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: 5 of 5 required status checks have not succeeded: 2 expected and 1 pending.
To https://github.com/quaquel/EMAworkbench.git
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/quaquel/EMAworkbench.git'

Fast-forward merge from a fork, for future reference:

git remote add EwoutH https://github.com/EwoutH/EMAworkbench.git
git fetch EwoutH performance-2
git checkout master
git merge --ff-only -S EwoutH/performance-2
git remote remove EwoutH

@quaquel quaquel merged commit 76d64c8 into quaquel:master Apr 2, 2023
@quaquel
Copy link
Copy Markdown
Owner

quaquel commented Apr 2, 2023

Thanks, with your script, it was easy for me to fix. I could not figure out how to give you the right to bypass checks.

@EwoutH
Copy link
Copy Markdown
Collaborator Author

EwoutH commented Apr 2, 2023

Awesome, thanks for merging!

When coming close to the 2.4.0 release I will do some benchmarks for overhead and general performance improvements compared to 2.3.0. I believe together with #232 we can reduce the overhead by at least 80%, promising a up to 5x performance improvement for really small models.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants