I’m wondering if the performance of the relayout function is dependent of the number of points plotted on the graph.
I’m working on a plot with roughly 6000 points. I’m adding and removing annotations via click events on the points or on the background (with help of an awful hack but without altering the plotly code mind you). I’ve noticed that adding and removing the annotation seems somewhat dependent of the number of points on the plot:
- for instance, when I zoom in to ~ 100 points, the annotation is displayed is about 1ms.
- yet for my whole sample, it takes well 1000ms to display said annotation.
I’ve timed a bit the function which puts the annotation, and the bottleneck seems to be the plotly.relayout function… which is a bit worrying since I thought relayout updated … well… the layout, so it shouldn’t depend on the number of points.
I’ve a little fiddle to illustrate this:
Any ideas on the why or how to optimize this?
Depending on what’s being updated, yes
relayout can trigger a full redraw.
In particular, as you described, adding or removing annotations currently triggers a full redraw. The reason being: adding or deleting and annotations may change a graph’s axis ranges and hence may change the data-to-pixel method use to draw traces.
As you might have noticed, there’s plenty of room for conditional improvements. For example, on graphs with set axis range, adding or deleting annotations should not lead to a re-rendering of the traces.
Thanks for the quick response.
adding or removing annotations currently triggers a full redraw. The reason being: adding or deleting and annotations may change a graph’s axis ranges and hence may change the data-to-pixel method use to draw traces.
That a bit of a pity, since I took great length to avoid having the annotation modifying the axes → using paper reference instead of data, etc…
The question would then be, what next? Is improving this feature in your plans to the short/middle or long term?
Do you know of any (not too awful) hack to improve this?