Bokeh is rendering very slow. Any suggestions?

Hi!

Just want to ask/understand why Bokeh takes a lot of time loading the embedded html of my layout. My layout has quite a lot of widgets, a worldmap plot and a datable and I’m using huge data (could this be the reason?) but bokeh can still plot everything well. I tried checking the time and found out that the backend moves really fast but the rendering is what needs some improving. Any suggestions how can I improve this?

Thanks in advance!

It’s impossible to offer concrete advice for a specific situation without real code to refer to. [1] If you can supply a Minimal Reproducible Example then we can take a look.


  1. And also all relevant package versions. You should always provide version information in any OSS support question on any forum. The answer may be wildly different e.g. if you are using Bokeh 1.4 or something. ↩︎

Hey! I’ll try my best to give you a glimpse of what I have implemented so far.

So I have a bunch of widgets, a world map plot and a data table which is paginated. What’s notable here is as well is the amount of data which I’m loading. And I’m also running the Bokeh Server under the Flask server

And here’s my code structure,

class MainApp:
: def init():
(initialize class)
def app(doc):
(get layout from SubApp.get_layout)
(instanciate SubApp class to get a new model for new session)

class SubApp:
def init():
(initialize class)
def callback_1(self):
def callback_2(self):
def callback_3(self):
def get_layout(self):
(Initialize widgets and plot)
(returns layout)

Some description about the data:

  • I’m loading a networkx graph model which contains approx 85k nodes and 180k edges.
  • These data are used for widgets options and for data of the datatable

Reasons why I think the app is slow to render,

  • Data is huge
  • App has too many widgets

It’s not usually possible to offer more than general advice for performance-related questions without being able to run and profile the code, and this case is no different. You will simply have to try some experiments:

  • Does using the WebGL backend help?
  • Do things improve if you reduce the data to very small subset?

If it is the data size that is the issue then an alternative would be to use Datashader instead of sending and plotting all the individual points.

Some versions have had issues with layout performance, so it’s not impossible that is relevant. But you have not provide the version information as I suggested above, so there is no way to speculate further. That said, this does not seem like very many widgets to me, regardless.

I forgot sharing the version I’m usin. My bad. So I’m using Bokeh 2.3.3 and I’m running it in a VM with the specs shown below,

image

I tried using webGL but the nodes and edges aren’t showing when I specify this configuration. I’m not sure if using graph renderer has something to do with this.

And yes, the rendering is just less than a second on fewer data.

Btw, just to clarify my issue is on the rendering of the embedded HTML. Like after the backend constructs the document, it takes some time before the plots and widgets appear on the browser.

And thanks for the suggestion. I’ll explore on DataShader. :slight_smile: