Calling Figure() is very slow

Hi,

I believe the 0.25s comes from some imports that are made the first time you call go.Figure in your application. You can try to profile the code to see if my assumption is correct. Figure can also be slow if you are constructing it with traces (it is not your case), since there are some data validations being made.

I wouldn’t rely on global variables, as it is well documented a bad idea… Instead, you can skip the Figure construction in Dash by using/updating the “figure” dictionary.

Dash serializes all the inputs and outputs in callbacks to JSON, including go.Figure objects. For instance, if you have a callback using the “figure” prop from a dcc.Graph component as Input or State, you can see that the fig is passed to the callback as a dictionary and not a go.Figure… You can make all sorts of updates and modifications by manipulating the dictionary, it just requires some familiarity with its structure (you can see an example here).

Hope this helps!

1 Like