I just started using Plotly with Python and I think I have found a significant speed up improvement in the graph_objs.py module.
Here are some details:
- I am creating a plot with 24 subplots that has 60 traces in each subplot
- Each trace contains 6 points.
- To generate this plot it took 1945 seconds, which seems like way too long
- I had a print state for each subplot and it progressively takes longer for each subplot
- I ran “kernprof” on the code looking specifically at the subroutine that I use to loop through the data to .append_trace to the figure
- I noticed that all the time was spent on the .append_trace function that is called out of graph_objs.py
- As I dug through graph_objs.py and found that line 936 contained “self[‘data’] += [trace]”
- In my limited understanding of python, I always heard this was a very inefficient way to do large string appends
- I changed line 936 to “self[‘data’].append(trace)”, which I believe is equivalent in function to “self[‘data’] += [trace]” but I think I have read that this is a much more efficient way to append
- This sped up the script to 8 seconds! A 243x improvement in speed.
From what I can tell, I think it is valid to change “self[‘data’] += [trace]” to “self[‘data’].append(trace)” but I am not sure of all the ramifications to other functionality. Is this a valid change to make and if so can graph_objs.py be updated with this?