Callbacks producing plotly graphs run extremely slow on first run only

I have a number of dash apps I am running which generally fall into one of two categories, displaying datatables or displaying plots. I have noticed that for those which display plots, any of the callbacks which produce the plots run extremely slowly the first time they are run, whereas after that they run almost instantly which is what I would expect from them. For example I have used the callback graph to look at how long they are taking and in one case I find that on the first run it takes 8 seconds for each callback to run but after this the average runtime will work down to the order of milliseconds if it is rerun many times through changing, removing, replotting the graph by adjusting input parameters. Is this known/expected behaviour? I can not find any information here on this? These graphs are plotly figures id dcc.Graph components btw. I do not see the same behaviour on apps which only produce datatables.

Did you find an answer to this? I’m having the same issue with plotly express, first run is super slow, and subsequent runs (even with different data), are almost instant.

Is the initial run just the one that is loading the dataframe from your source? After that is it just callbacks that are manipulating or reusing the data held in the dataframe?

I haven’t had that problem myself, even with chained callbacks updating 4 graphs, but my project is running on my local machine. Maybe in production and/or under heavier load it would appear.

I encountered this issue of initial plotly express plots being slow too. It’s typically upwards of 10 seconds between calling the plot and seeing it in frontend.

What I did to solve it was to pre-call plotly at the start when anyone lands on the webpage. At the backend which is Flask, I use a function to create a simple dummy plotly plot which is not output to anywhere.

Then, subsequent ‘real’ calls to plots are faster, reduced to about below 3 seconds.

1 Like