How to properly optimize CPU and memory usage

As quick update (in case anyone runs into this thread because of google):

Making sure you’re using the Renderer lock got rid of the problem for me completely. Memory usage was still pretty high, but now the app wasn’t completely crashing. It even sustained a mild reddit hug of death.

For the long term though:

  • I adapted my code to use plotly instead of matplotlib to take some of the edge off and just have the browser do most of the work. Plus you get to make the plots interactive.
  • Do garbage collection after each run of the script

These measures lowered my memory usage from ~50% to ~12.5%

1 Like