Skip to content

Commit

Permalink
Improvements for reducing queued server events
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 13, 2020
1 parent d5912c2 commit 4cfa566
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion holoviews/plotting/bokeh/callbacks.py
Expand Up @@ -308,9 +308,12 @@ class ServerCallback(MessageCallback):
Stream(s) attached to the callback.
"""

_batched = []

def __init__(self, plot, streams, source, **params):
super(ServerCallback, self).__init__(plot, streams, source, **params)
self._active = False
self._prev_msg = None


@classmethod
Expand Down Expand Up @@ -343,6 +346,9 @@ def on_change(self, attr, old, new):
value change at once rather than firing off multiple plot updates.
"""
self._queue.append((attr, old, new))
if self._batched and not all(b in [q[0] for q in self._queue] for b in self._batched):
return # Skip until all batched events have arrived

if not self._active and self.plot.document:
self._active = True
if self.plot.document.session_context:
Expand Down Expand Up @@ -408,7 +414,13 @@ def process_on_change(self):
cb_obj = self.plot_handles.get(obj_handle)
msg[attr] = self.resolve_attr_spec(path, cb_obj)

self.on_msg(msg)
try:
equal = msg == self._prev_msg
except Exception:
equal = False
if not equal:
self.on_msg(msg)
self._prev_msg = msg

if self.plot.document.session_context:
self.plot.document.add_timeout_callback(self.process_on_change, 50)
Expand Down Expand Up @@ -785,6 +797,8 @@ class RangeXYCallback(Callback):
models = ['x_range', 'y_range']
on_changes = ['start', 'end']

_batched = on_changes

def _process_msg(self, msg):
data = {}
if 'x0' in msg and 'x1' in msg:
Expand Down

0 comments on commit 4cfa566

Please sign in to comment.