Circle-like glyph renderers shared by multiple figures can cause page to freeze after changing a figure's range

Hi - this issue arose for me starting with Bokeh 2.2.0. I’ve found that if you add one figure’s circle renderer to another figure, then if any of the circles exit the range of either of the figures, the webpage freezes. I also found the same result with other glyph renderers like diamonds and crosses. Lines work, however.

I’m using firefox, python 3.6.8, ubuntu 18.04.

Here’s a minimal example to reproduce it with bokeh serve:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import row

# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# create a figure and plot some circles 
p1 = figure(title="first", x_axis_label='x', y_axis_label='y')
c = p1.circle(x, y, size=8)

# create another figure that will plot the above circles as well
p2 = figure(title='second', x_axis_label='x', y_axis_label='y')
p2.renderers.append(c)

# try setting the range of one of the plots in a way that should hide some circles
# this freezes the app using either x or y ranges for either p1 or p2 figures
p1.x_range.start=0
p1.x_range.end=3

curdoc().add_root(row(p1, p2))

I guess my ultimate question is: is this a genuine bug, or is this just me abusing the library in a way I can’t get away with anymore :stuck_out_tongue:? Thanks

is this just me abusing the library in a way I can’t get away with anymore

I’m pretty sure that’s the case. You generally don’t want to change renderers directly. And you especially don’t want to share such simple models as renderers. Just put all the data into a common ColumnDataSource and call the circle function twice. Thus the data, usually the most “heavy” part of the whole setup, will be shared.

Historically, I can definitely say that sharing renderers between plots has never been supported, in the sense that that has never been intended usage that was explicitly maintained under test. There has never been any demonstration of that usage in the docs or examples. However, it’s not uncommon for things to accidentally or unintentionally “work” in some capacity (until they don’t) and I suppose this is one of those cases.

In any event, I second @p-himik’s advice to share the CDS instead as the best alternative.

Ok, thanks! I figured that that might be the case ;).