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 python threading instead of solara thread in model controller #2303

Conversation

wang-boyu
Copy link
Member

This seems to speed up model execution as a fix to what was reported in #2289 (comment) and following comments. But I don't really know why.

@wang-boyu wang-boyu added the maintenance Release notes label label Sep 19, 2024
@rht
Copy link
Contributor

rht commented Sep 19, 2024

I assume this solution also works on Colab?

@wang-boyu
Copy link
Member Author

Oh sorry I've been testing it on my laptop; didn't try colab!

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.0% [+0.3%, +1.6%] 🔵 +0.2% [-0.0%, +0.3%]
BoltzmannWealth large 🔵 +23.2% [-0.4%, +69.5%] 🔵 -0.8% [-3.9%, +1.4%]
Schelling small 🔵 +0.4% [+0.0%, +0.8%] 🔵 -0.4% [-0.6%, -0.2%]
Schelling large 🔵 +0.3% [-0.2%, +0.8%] 🔵 +1.7% [-0.3%, +3.9%]
WolfSheep small 🔵 -0.2% [-0.4%, +0.1%] 🔵 +0.3% [+0.1%, +0.5%]
WolfSheep large 🔵 -0.0% [-0.9%, +0.8%] 🔵 +1.1% [-0.3%, +2.3%]
BoidFlockers small 🔵 -1.5% [-1.9%, -1.1%] 🔵 +0.0% [-0.7%, +0.8%]
BoidFlockers large 🔵 -1.1% [-1.5%, -0.7%] 🔵 -0.1% [-1.0%, +0.9%]

@wang-boyu
Copy link
Member Author

Btw it's probably worth mentioning that it's good that play and pause buttons are merged into one (in PR #2299). Otherwise the solara app runs into trouble if users keep clicking on the play button.

@Corvince
Copy link
Contributor

Wow, this runs indeed a lot faster. But I was worried about the implications of using threads, since they potentially keep running forever in the background. use_thread does a lot to prevent this, but this seems to be quite slow for that reason. I now saw that its also deprecated and there is use_task, which also allows running in the python event loop. Its equally fast compared to this PR, but potentially saves us some headaches in the future. See #2304

@Corvince Corvince closed this Sep 20, 2024
@Corvince
Copy link
Contributor

Again, thanks a lot for showing whats possible. Its way faster now, would not have happened without your effort/noticing of bad performance

@wang-boyu wang-boyu deleted the viz/threading-in-model-controller branch September 20, 2024 13:51
@wang-boyu
Copy link
Member Author

Great! Thanks @Corvince

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

Successfully merging this pull request may close these issues.

3 participants