Throwing Error in "plotly_hover" boosts hover performance

Greetings!

I found an interesting bug where if you purposefully throw an error inside a function for a plotly hover listener (both “plotly_hover”/“plotly_unhover” works), the hover labels and spike lines actually redraw A LOT faster.

I wrote a quick pen that demonstrates this, just toggle the 4th line on and off to see the difference.
A couple quick notes:

  1. graph will look different on refresh because it’s random data
  2. This is more noticeable when you have a larger dataset like 300 to 400+

https://codepen.io/p1ho/pen/jKoJLe

Functionally I haven’t found any problems throwing that error might cause unless you have custom stuff you actually want to execute on “plotly_hover”/“plotly_unhover”.

Now obviously the downside is you would get this barrage of errors in your console log.

Can someone please elaborate why this is? I would really love that hover performance when I don’t have to use a hacky solution such as throwing an error.

Thanks in advance!!!

EDIT 1:

  1. I found out with the error throwing version, the cpu usage of the page goes up higher (~5%) compared to the normal version (2-3 %)
  2. In the error log, there is something called Object.r.throttle from the plotly.js file, this made me think I somehow bypassed the default throttle by throwing an error which led to the performance boost.

If #2 is true, do we have control for how much throttling we want?

No we don’t expose a way to tweak the throttle interval value. You’ll have to fork our repo and tweak this line.

1 Like

Got it! Thank you so much!!

1 Like