Slow performance with Holoviews live data

A quick update on this. The Bokeh-based approach was indeed much faster.

The fps is somewhere between 55-100fps. The in-notebook timing is not accurate as the data gets queued up to be sent asynchronously and the notebook cell completes executing before all the data is sent. I’m just estimating fps based on when the graph finishes updating. But, this is good enough for my needs now.

In a Jupyter notebook:

import time
from bokeh.plotting import figure
import panel as pn
import numpy as np
pn.extension()

TIME_RANGE = 5.15
FRAMES = 160
N_BINS = 512

spec_buffer = np.random.rand(N_BINS, FRAMES)
activation_buffer = np.random.rand(FRAMES)

OPTS = dict(plot_width=800, plot_height=300,
              tools="xpan,reset,save,xwheel_zoom",
              x_range=[-TIME_RANGE, 0],
           )

fig1 = figure(**OPTS, title="spectrogram", y_range=[0, N_BINS])
spec_plot = fig1.image([spec_buffer], x=-TIME_RANGE, y=0, dw=TIME_RANGE, dh=N_BINS)

fig2 = figure(**OPTS, title="activation", y_range=[0, 1])
act_plot = fig2.line(np.linspace(-TIME_RANGE, 0, FRAMES), activation_buffer)

pane = pn.Pane(pn.Column(fig1, fig2))

def shift_in(target, src):
    n = src.shape[-1]
    target[..., :-n] = target[..., n:]
    target[..., -n:] = src

pane
%%time

iters = 500
start = time.time()
last = start
for i in range(iters):
    shift_in(spec_buffer, np.random.rand(N_BINS, 1))
    shift_in(activation_buffer, np.random.rand(1))
    
    spec_plot.data_source.data['image'] = [spec_buffer]
    act_plot.data_source.data['y'] = activation_buffer
    pn.io.push_notebook(pane)
    
    now = time.time()
    last = now
print(f"{iters / (time.time() - start):.2f} fps average")
2 Likes