-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Improve visualization performance through multi-threading #2604
Description
Mesa currently runs model execution and visualization rendering on the same thread, creating performance bottlenecks when running computationally intensive models with multiple visualizations. This impacts responsiveness, especially in Jupyter notebooks. The UI can lag or freeze during model execution since visualization updates block the main thread.
We could improve performance by leveraging Solara's use_thread() functionality to run visualizations on separate threads from model execution. This would allow the model to continue executing while visualizations update asynchronously.
There could be (at least) three threads:
- Main thread for model execution
- Separate thread for Solara UI/event handling
- Worker thread pool for rendering visualizations (plots, space drawings, etc.)
Some key questions to resolve:
- How to handle thread synchronization between model and vis? (and how much is need? One direction or bi?)
- Should threading be configurable or always enabled?
- Thread per component vs shared thread pool?
Next steps would be to prototype basic thread separation, benchmark improvements, and document the threading behavior.
See also:
- Solara threading docs & examples: https://solara.dev/documentation/api/hooks/use_thread
- Mesa visualization code: https://github.com/projectmesa/mesa/tree/main/mesa/visualization