Large data & performance

How to keep a shinywidgets app fast as data, traffic, or interaction frequency grows: update widgets in place instead of re-rendering them, pick the right renderer for your data size, share a widget across sessions without paying for it per session, and budget for the JavaScript a user downloads before they see anything.

The numbers on this page come from measuring a real Shiny app – websocket frames, HTTP responses, server memory – not from reading source code. Treat them as a sense of scale (and a “measure it before you assume” habit), not as guarantees for your own data and hardware.

This page opens with the three strategies that cover every widget in this roster that handles large data, then answers five narrower questions, each its own section below:

  1. Re-render vs. in-place update – when a widget changes, should your code build a new one or mutate the existing one? How much does the choice cost in bytes, and what does it preserve?
  2. Big data: choosing the right widget – at 10 thousand, 100 thousand, and a million points, how do six large-data renderers compare?
  3. Lifetimes and memory – what does session_lifetime() vs. shared_lifetime() cost in server RAM as concurrent sessions pile up?
  4. Rate limiting – does rate_policy/rate_delay actually do anything for the accessor you’re reading?
  5. Bundle size and first load – how many bytes does a user download before any of this matters?

This article assumes you’ve read Reacting to widgets for the accessor mental model, lifetimes, and rate-limiting concepts; this page goes one level deeper on why the numbers come out the way they do.

Three approaches to large data

Every widget in this roster that handles large data does it with one of three strategies. Picking the right one (or combining two, as the linked-views article’s pattern 7 does, below) matters more than which specific library you reach for within a strategy.

  1. Draw it with the GPU in the browser. Send the real points to the browser and let the GPU handle per-point rendering and hit-testing: plotly’s Scattergl/render_mode="webgl", bokeh’s figure(output_backend="webgl"), jscatter, and lonboard. Payload and render time both scale with point count (Section 2 below), but you get real per-point interaction – lasso, hover, pick – that a server-side image can’t offer.
  2. Summarize on the server. Aggregate before anything crosses the wire, so the payload is sized by the output (screen pixels, bin count), not the input (row count): datashader (rasterize/datashade, via HoloViews) and VegaFusion for altair. This is the only strategy of the three that stays flat as data grows into the tens of millions of rows (Section 2 below).
  3. Only send what’s visible. Keep the data server-side (or in a server-managed query engine) and ship only the current page, view, or query result: perspective‘s virtualized table, mosaic and quak via DuckDB, and itables’ maxBytes downsampling (see the itables guide).

These aren’t mutually exclusive. The linked-views article’s “Brushing large data: push summaries, not points” pattern combines (1) and (2) – a GPU-drawn raster for the dense view, server-summarized histograms for the linked controls – and measures bytes per brush step for both. Its one-sentence finding is the principle behind all three strategies above: a brush (or any interaction) step’s cost should be a function of what it ships, not what it’s computed from – push a summary, not the rows.

1. Re-render vs. in-place update

A render function that reads nothing but its own module-level data runs once and never again: every update has to come from somewhere else, and there are exactly two ways to deliver it. Re-render means the render function runs again and returns a brand new widget – new zoom level, new selection, new everything, and (for an anywidget-based widget) another full copy of its JavaScript bundle. In-place update means a @reactive.effect mutates the existing widget’s trait (plot.widget.data[0].marker.color = ..., layer.get_fill_color = ...) and only the changed trait crosses the wire.

Three widgets, one apples-to-apples test each: two buttons wired to the identical visual change (toggle a color), one driving a @reactive.effect that mutates the live widget, the other driving a reactive.value that forces the render function to run again. Each row sums the websocket bytes for one click.

Widget Change In-place bytes Re-render bytes Ratio
plotly (5,000 points) marker color ~36 KB ~5.5 MB ~150x
lonboard (50,000 points) per-point fill color ~140 KB ~6.2 MB ~45x
ipyleaflet (177-country choropleth) layer.visible toggle a few hundred bytes ~1.1 MB thousands of times
ipyleaflet (same choropleth) layer.style color ~1.1 MB ~1.1 MB ~1x (see below)

The three apps (lonboard: examples/02_inplace_lonboard.py; ipyleaflet: examples/03_inplace_ipyleaflet.py). The plotly one (examples/01_inplace_plotly.py):

import numpy as np
import pandas as pd
import plotly.express as px
from shiny import reactive
from shiny.express import input, ui
from shinywidgets import render_plotly

ui.page_opts(title="plotly: re-render vs in-place", fillable=True)

N = 5000
rng = np.random.default_rng(42)
df = pd.DataFrame({"x": rng.normal(size=N), "y": rng.normal(size=N)})

ui.input_action_button("inplace", "Update in place (batch_update)")
ui.input_action_button("rerender", "Force re-render (new figure)")

color_toggle = reactive.value(False)
rerender_trigger = reactive.value(0)


@render_plotly
def plot():
    # Reads rerender_trigger so clicking "rerender" forces a fresh figure;
    # the in-place path never touches this and so never re-enters here.
    rerender_trigger()
    with reactive.isolate():
        is_red = color_toggle()
    color = "red" if is_red else "blue"
    fig = px.scatter(df, x="x", y="y", color_discrete_sequence=[color])
    return fig.update_traces(marker=dict(size=4))


@reactive.effect
@reactive.event(input.inplace)
def _inplace():
    with reactive.isolate():
        is_red = not color_toggle()
    color_toggle.set(is_red)
    with plot.widget.batch_update():
        for trace in plot.widget.data:
            trace.marker.color = "red" if is_red else "blue"


@reactive.effect
@reactive.event(input.rerender)
def _rerender():
    with reactive.isolate():
        color_toggle.set(not color_toggle())
    rerender_trigger.set(rerender_trigger() + 1)

Why re-render costs so much more than the data itself

5,000 points of x/y float data is only tens of kilobytes either way. The reason the re-render case runs into the megabytes: the new FigureWidget’s state includes an _esm field – the entire plotly.js bundle, re-sent as part of the widget’s own state, every single re-render. In-place’s batch_update() never creates a new model, so it never touches _esm at all; only the changed marker.color buffer crosses the wire.

lonboard shows the same shape for a different reason: its re-render resends both the point positions (which never changed) and lonboard’s own deck.gl/maplibre JavaScript, where in-place only resends the one Arrow buffer that changed (the color column):

import geopandas as gpd
import numpy as np
from lonboard import Map, ScatterplotLayer
from shiny import reactive
from shiny.express import input, ui
from shinywidgets import render_lonboard

ui.page_opts(title="lonboard: re-render vs in-place", fillable=True)

N = 50_000
rng = np.random.default_rng(42)
lon = rng.uniform(-122.6, -122.3, N)
lat = rng.uniform(37.6, 37.85, N)
POINTS = gpd.GeoDataFrame(geometry=gpd.points_from_xy(lon, lat), crs="EPSG:4326")

ui.input_action_button("inplace", "Update in place (set get_fill_color)")
ui.input_action_button("rerender", "Force re-render (new Map)")

color_toggle = reactive.value(False)
rerender_trigger = reactive.value(0)


# Per-point varying colors (not a constant RGB triple) so the measured
# payload reflects real per-point data, not a degenerate, highly
# compressible constant array.
_rank = np.argsort(np.argsort(lon)) / N


def colors(is_red: bool) -> np.ndarray:
    r = (_rank * 255).astype("uint8")
    out = np.zeros((N, 3), dtype="uint8")
    if is_red:
        out[:, 0] = r
        out[:, 2] = 255 - r
    else:
        out[:, 2] = r
        out[:, 0] = 255 - r
    return out


@render_lonboard
def map():
    rerender_trigger()
    with reactive.isolate():
        is_red = color_toggle()
    layer = ScatterplotLayer.from_geopandas(
        POINTS, get_fill_color=colors(is_red), get_radius=20
    )
    return Map(layer)


@reactive.effect
@reactive.event(input.inplace)
def _inplace():
    with reactive.isolate():
        is_red = not color_toggle()
    color_toggle.set(is_red)
    map.widget.layers[0].get_fill_color = colors(is_red)


@reactive.effect
@reactive.event(input.rerender)
def _rerender():
    with reactive.isolate():
        color_toggle.set(not color_toggle())
    rerender_trigger.set(rerender_trigger() + 1)

Zooming in on each map before clicking either button shows what the bytes difference buys you:

plotly zoomed in

After in-place color update, still zoomed to the identical range:

plotly after in-place, zoom preserved

After re-render, zoomed back out to the figure’s original extent – the color changed, but so did everything else:

plotly after re-render, zoom lost

lonboard tells the identical story with camera state instead of axis ranges – zoomed in to a “2 km” scale bar before either button, still at “2 km” after in-place, back to the map’s default “5 km” fit-to-data view after re-render:

When “in-place” doesn’t actually save bytes

The ipyleaflet row above has two different in-place updates on the exact same countries GeoJSON layer, and they tell opposite stories. Toggling layer.visible (a plain boolean trait) costs a few hundred bytes – the textbook case. Setting layer.style costs about as much as a full re-render.

ipyleaflet choropleth: 177 countries

The reason is upstream, not a shinywidgets limitation: ipyleaflet’s GeoJSON class observes its own style trait and, on every change, rebuilds its data trait by baking the style into each feature’s properties (ipyleaflet.GeoJSON._get_data()) – so any style change re-syncs the entire feature collection, not just a small style object. There is no cheaper way to recolor a GeoJSON layer in ipyleaflet; if you need cheap restyling of many features, a vector-tile-backed map (maplibre, lonboard) or a layer whose style is separate from its data is the better fit. This is worth knowing before you assume “in-place” is a blanket win – verify what actually crosses the wire for the trait you’re setting.

import json
import urllib.request

import ipyleaflet as L
from shiny import reactive
from shiny.express import input, ui
from shinywidgets import render_ipyleaflet

ui.page_opts(title="ipyleaflet: re-render vs in-place", fillable=True)

COUNTRIES_URL = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson"
with urllib.request.urlopen(COUNTRIES_URL) as resp:
    COUNTRIES = json.load(resp)

ui.input_action_button("inplace", "Update in place (set layer.style)")
ui.input_action_button("rerender", "Force re-render (new Map)")
ui.input_action_button("toggle_visible", "Toggle layer.visible (in place)")

color_toggle = reactive.value(False)
rerender_trigger = reactive.value(0)


def style(is_red: bool) -> dict:
    return {"color": "red" if is_red else "blue", "fillOpacity": 0.3, "weight": 1}


@render_ipyleaflet
def map():
    rerender_trigger()
    with reactive.isolate():
        is_red = color_toggle()
    m = L.Map(center=(20, 0), zoom=2)
    m.add(L.GeoJSON(data=COUNTRIES, style=style(is_red), name="countries"))
    return m


def countries_layer():
    return next(lyr for lyr in map.widget.layers if lyr.name == "countries")


@reactive.effect
@reactive.event(input.inplace)
def _inplace():
    with reactive.isolate():
        is_red = not color_toggle()
    color_toggle.set(is_red)
    countries_layer().style = style(is_red)


@reactive.effect
@reactive.event(input.rerender)
def _rerender():
    with reactive.isolate():
        color_toggle.set(not color_toggle())
    rerender_trigger.set(rerender_trigger() + 1)


@reactive.effect
@reactive.event(input.toggle_visible)
def _toggle_visible():
    layer = countries_layer()
    layer.visible = not layer.visible

This table doesn’t report wall-clock time: on localhost, network transfer is never the bottleneck, so a timer here mostly measures server-side serialization and can make the bigger payload look faster by accident. Section 2 below compares payloads at a scale where they matter.

pyvista’s in-place re-render dropped from a roughly 1 MB floor to a few KB for an unchanged mesh once its vtk.js runtime became a per-session singleton instead of a per-render resend – see the pyvista guide. keplergl’s playback/animation stream can fire many raw config syncs per second unthrottled vs. about 2/second throttled – see the keplergl guide.

2. Big data: choosing the right widget

At 10,000 / 100,000 / 1,000,000 synthetic points, six renderers’ initial payload:

Renderer Transport 10K bytes 100K bytes 1M bytes
plotly (Scattergl) binary buffer ~5.6 MB ~7.5 MB ~27 MB
jscatter binary buffer ~2.5 MB ~4.5 MB ~24 MB
lonboard GeoArrow binary ~5 MB ~7 MB ~25 MB
perspective virtualized (server-side table) ~6.5 MB ~6.5 MB not run*
datashader (rasterize, via holoviews) server-rasterized image, binary buffer ~2.2 MB ~2.3 MB ~2.4 MB
embedding-atlas binary buffer (positions + text) ~6 MB ~7 MB ~16 MB

* perspective’s payload is flat from 10K to 100K rows (see below), so a 1M-row run would repeat that result for the same architectural reason.

datashader’s flatness holds another order of magnitude further: pushed to 10,000,000 points – a scale none of the other renderers in this table can even attempt – the rasterized image stays about the same size, a small increase for 1,000x the data. embedding-atlas does not get this flatness for free: its GPU map needs the real points client-side, the same way the three scatter renderers above do, so its payload grows with N – it belongs with “draw it with the GPU in the browser” for transport purposes, even though its auto-labeling, charts, and SQL cross-filter put it in a different category on the sidebar. Its render time grows with N too, unlike datashader’s, which stays flat – the same story bytes tell, for the same reason.

The four apps (examples/05_bigdata_jscatter.py, examples/06_bigdata_lonboard.py, and examples/07_bigdata_perspective.py follow the same shape). The plotly one (examples/04_bigdata_plotly.py):

import os

import numpy as np
import pandas as pd
import plotly.graph_objects as go
from shiny.express import ui
from shinywidgets import render_plotly

N = int(os.environ.get("PERF_N", "10000"))
rng = np.random.default_rng(42)
df = pd.DataFrame({"x": rng.normal(size=N), "y": rng.normal(size=N)})

ui.page_opts(title=f"plotly scattergl: {N:,} points", fillable=True)


@render_plotly
def plot():
    return go.FigureWidget(
        data=[go.Scattergl(x=df["x"], y=df["y"], mode="markers", marker=dict(size=3))]
    )

examples/04_bigdata_plotly.py (run with PERF_N=100000 uv run shiny run ...)

100,000 points, all three scatter-style renderers, all rendered successfully and panned/zoomed interactively in the browser:

100,000 points again, but the two new rows – a rasterized image (datashader) instead of individual marks, and embedding-atlas’s GPU map plus its auto-generated table:

examples/15_bigdata_datashader.py, examples/16_bigdata_embedding_atlas.py

The real story isn’t “JSON vs. binary” – it’s bundle size and client-side cost

It’s tempting to assume plotly sends inefficient JSON text while jscatter and lonboard send efficient binary buffers, and that’s why plotly is bigger. It isn’t: plotly’s Scattergl trace data travels as binary arrays just like jscatter’s and lonboard’s. The marginal cost per point is essentially the same rate, about 20-21 bytes/point on the wire (two float64 coordinates, base64-encoded), for all three libraries. The story is a fixed one-time bundle cost, not a per-point transport difference:

Renderer Extrapolated bundle (N->0) Marginal cost/point
jscatter ~2.3 MB ~21 B
lonboard ~4.8-5.1 MB ~20-22 B
plotly ~5.4 MB ~21 B

The bundle is paid once per browser session regardless of row count; the per-point rate is what makes the curve climb afterward. That changes the decision: for a few hundred thousand points, jscatter’s much lighter bundle wins on cold-start bytes even though its marginal per-point rate is no better than plotly’s. It also explains why plotly took roughly twice as long to render 1M points as jscatter or lonboard despite similar byte counts: plotly.js’s SVG/WebGL setup and trace processing is simply slower per point than regl-scatterplot (jscatter) or deck.gl (lonboard) at this scale, a client-side cost that bytes alone don’t capture.

perspective doesn’t pay for row count at all

perspective’s payload is identical at 10,000 and 100,000 rows (~6.5 MB both times): render_perspective keeps the actual table on a server-side Perspective engine, and the browser’s viewer queries that server for only the visible rows of its current view – the same virtual-scrolling architecture that makes a spreadsheet UI usable at any row count. That payload is almost entirely perspective’s own WASM analytics engine (see Section 5), paid once regardless of whether your table has 10 rows or 10 million. This is the cleanest argument for not reaching for a scatter-plot renderer when what you actually have is tabular data someone wants to browse, filter, and sort: a virtualized table scales where a point cloud doesn’t.

datashader: the payload is an image, not the data

The two new rows above aren’t scatter renderers competing on the same transport, so they don’t belong in the “bundle plus ~20 bytes/point” story above – each has its own shape:

import os

import holoviews as hv
import numpy as np
import pandas as pd
from holoviews.operation.datashader import rasterize
from shiny.express import ui
from shinywidgets import render_holoviews

hv.extension("bokeh")

N = int(os.environ.get("PERF_N", "10000"))
rng = np.random.default_rng(42)
df = pd.DataFrame({"x": rng.normal(size=N), "y": rng.normal(size=N)})

ui.page_opts(title=f"datashader rasterize: {N:,} points", fillable=True)


@render_holoviews
def plot():
    # A fixed pixel size (not responsive=True) isolates the payload's
    # dependence on N from its dependence on viewport/DPI -- the point of
    # this example is that the former is flat, which a responsive size
    # would otherwise confound.
    points = hv.Points(df, ["x", "y"])
    return rasterize(points, width=700, height=450).opts(
        width=700, height=450, cmap="fire", cnorm="eq_hist", colorbar=True
    )

rasterize() bins every point into a 700x450 grid on the server before anything crosses the wire, so the payload is the image (plus the surrounding Bokeh document’s own JSON, which is the fixed majority of these bytes at this image size), not the data – it barely moves between 10K points and 1M. See the datashader guide’s own Payload and latency at scale section.

embedding-atlas’s climb over the same range is the opposite shape, for a specific reason: unlike datashader, its WebGPU scatter map draws the real points on the client, so EmbeddingAtlasWidget has to ship every row’s x/y (and, in this example, a short text string) to the browser up front, the same architectural choice jscatter and lonboard make above. Its DuckDB cross-filter still runs server-side afterward (see the embedding-atlas guide), but that doesn’t change what the initial payload costs.

examples/16_bigdata_embedding_atlas.py

Does attaching every accessor at render cost anything?

A renderer’s accessors attach the moment its output renders, whether or not the app ever reads them (plotly’s selected/selecting/brushing/hover are the exception, along with selected_rows, which reads selected: they’re opt-in via listen_to=[...], because their payloads grow with the selection or stream continuously). plotly’s output carries eleven accessors altogether – ten browser-side event bridges, plus selected_rows, which derives from selected – none of which examples/04_bigdata_plotly.py above reads or declares. Attaching an accessor just registers a message handler; it doesn’t move data, so it doesn’t show up in the 10K/100K/1M timing above and shouldn’t scale with point count or accessor count. For plotly’s current set, eager attachment is not a measurable tax – worth re-checking only if a future renderer accumulates a much larger accessor set.

What this means for picking a renderer

  • A few thousand to a few hundred thousand points, interactive pan/zoom/lasso: jscatter’s bundle is the lightest of the three scatter renderers here: pick it unless you specifically need lonboard’s map projections/basemap or plotly’s broader chart-type ecosystem (facets, subplots, non-scatter traces on the same figure).
  • Up to a million points: all three render, but budget for the bundle (a few MB) plus about 20 bytes/point, and expect plotly to take roughly 2x as long on the client as the other two at this scale.
  • Tabular browsing (sort/filter/aggregate), even millions of rows: perspective (or itables with server-side processing) sidesteps the whole “ship everything” problem; see the itables guide’s own virtualization note for the equivalent story on its maxBytes downsampling.
  • Tens of millions of rows and up, as a dense overview: datashader stays flat from 10K to 10M points because the payload is an image, not the data – reach for it once a raw scatter stops being viable at all (the datashader guide found a plain scatter didn’t even finish transferring 10,000,000 points within a reasonable time).
  • Embedding/cluster exploration with auto-labeling, charts, and SQL filtering built in: embedding-atlas, but budget for its payload like the GPU scatter renderers above (several MB at 10K, growing into the tens of MB at 1M) – it doesn’t get datashader’s flatness, because its map needs the real points client-side.

3. Lifetimes and memory

Updating in place covers what session_lifetime() and shared_lifetime() preserve functionally. Here’s what they cost in server RAM: building a 200,000-point lonboard ScatterplotLayer fresh per session adds tens of megabytes of server RAM for every concurrent session, while building the same layer once via shared_lifetime() in a sibling globals.py (the Express gotcha the other article documents) keeps memory flat regardless of how many sessions are connected – shared_lifetime()’s baseline is higher up front, because the cost is paid once at import time, before any session connects, instead of amortized per session.

The two apps (the shared one is examples/lifetimes/09_lifetimes_memory_shared.py + examples/lifetimes/globals.py, both shown below). Per-session (examples/lifetimes/08_lifetimes_memory_persession.py):

import geopandas as gpd
import numpy as np
from lonboard import Map, ScatterplotLayer
from shiny.express import ui
from shinywidgets import render_lonboard

N = 200_000

ui.page_opts(title="memory: per-session widget", fillable=True)


@render_lonboard
def map():
    # Each session builds its OWN 200k-point layer -- memory for this widget
    # scales with the number of concurrent sessions.
    rng = np.random.default_rng(42)
    lon = rng.uniform(-122.6, -122.3, N)
    lat = rng.uniform(37.6, 37.85, N)
    points = gpd.GeoDataFrame(geometry=gpd.points_from_xy(lon, lat), crs="EPSG:4326")
    layer = ScatterplotLayer.from_geopandas(points, get_radius=20)
    return Map(layer)

vs. the shared version, where the widget is built once in a sibling module (examples/lifetimes/globals.py):

# Built once, at import time, before any session exists -- Express imports
# this sibling module before any session connects (not necessarily exactly
# once: see the "Lifetimes" article's shared_lifetime()-in-Express gotcha
# for why, and for why this can't live in the main app file directly).
import geopandas as gpd
import numpy as np
from lonboard import Map, ScatterplotLayer
from shinywidgets import shared_lifetime

N = 200_000

with shared_lifetime():
    rng = np.random.default_rng(42)
    lon = rng.uniform(-122.6, -122.3, N)
    lat = rng.uniform(37.6, 37.85, N)
    _points = gpd.GeoDataFrame(geometry=gpd.points_from_xy(lon, lat), crs="EPSG:4326")
    _layer = ScatterplotLayer.from_geopandas(_points, get_radius=20)
    SHARED_MAP = Map(_layer)

and the app itself just returns the shared instance (examples/lifetimes/09_lifetimes_memory_shared.py):

from globals import SHARED_MAP
from shiny.express import ui
from shinywidgets import render_lonboard

ui.page_opts(title="memory: shared_lifetime widget", fillable=True)


@render_lonboard
def map():
    # Every session is shown the SAME Map instance (built once, at import
    # time, in globals.py -- see the "Lifetimes" article's shared_lifetime()
    # + Express gotcha for why it can't be built directly in this file).
    # Memory for this widget does not scale with the number of concurrent
    # sessions.
    return SHARED_MAP

The per-session numbers are noisy run to run (Python’s allocator doesn’t always return freed memory promptly), but the shape holds: per-session memory climbs by tens of megabytes per concurrent session (roughly 15-35 MB/session net), while shared_lifetime()’s memory is flat regardless of whether 3 or 5 sessions are connected, because every session is looking at the same Python object. For N concurrent sessions viewing the same heavy, read-mostly dataset, shared_lifetime() turns an O(N) memory cost into O(1) – at the price (documented in the other article) that every session can see, and move, the same shared state.

4. Rate limiting

Reacting to widgets already showed the headline contrast (render_plotly’s selecting(), which declares a default debounce, fires far less often than the same drag with rate_delay=0). ipydatagrid’s selected() and lonboard’s view_state() both declare a default debounce too (0.25s; #400). The ipydatagrid guide has the clean before/after: a drag publishes .selected() only when the pointer pauses, against one update per pointer move for an un-rate-limited reactive_read() on the same trait – ipydatagrid’s raw trait really does stream on every pointer move, so the default debounce visibly collapses it.

lonboard’s view_state() is a more interesting case: the declared default debounce is real, but it’s very hard to observe from a single ordinary gesture, for a reason that has nothing to do with shinywidgets. Two identical lonboard maps, one default, one rate_delay=0, each counting view_state() fires via an effect during an identical 10-step scroll-zoom burst on its own canvas:

import geopandas as gpd
import numpy as np
from lonboard import Map, ScatterplotLayer
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_lonboard

ui.page_opts(title="lonboard view_state(): debounced vs. rate_delay=0", fillable=True)

rng = np.random.default_rng(42)
lon = rng.uniform(-122.6, -122.3, 2000)
lat = rng.uniform(37.6, 37.85, 2000)
POINTS = gpd.GeoDataFrame(geometry=gpd.points_from_xy(lon, lat), crs="EPSG:4326")


def counter():
    n = reactive.value(0)

    def bump():
        with reactive.isolate():
            n.set(n() + 1)

    return n, bump


with ui.layout_columns():
    with ui.card(full_screen=True):
        ui.card_header("default rate_policy/rate_delay")

        @render_lonboard
        def map_default():
            return Map(ScatterplotLayer.from_geopandas(POINTS, get_radius=30))

        n_default, bump_default = counter()

        @reactive.effect
        def _():
            map_default.view_state()
            bump_default()

        @render.code
        def out_default():
            return f"view_state() fired {n_default()} times"

    with ui.card(full_screen=True):
        ui.card_header("rate_delay=0 (same renderer kwarg)")

        @render_lonboard(rate_delay=0)
        def map_fast():
            return Map(ScatterplotLayer.from_geopandas(POINTS, get_radius=30))

        n_fast, bump_fast = counter()

        @reactive.effect
        def _():
            map_fast.view_state()
            bump_fast()

        @render.code
        def out_fast():
            return f"view_state() fired {n_fast()} times"

both maps fired view_state() the same number of times for an identical zoom burst

Both panels fired the same low count for the identical zoom burst. The reason is upstream of shinywidgets: lonboard’s own bundled JS already debounces its browser-to-Python trait sync at 300ms, a window close to shinywidgets’ own 0.25s default. By the time a raw update reaches shinywidgets’ rate-limiting layer, lonboard has usually already collapsed the gesture to one message, so there’s nothing left for rate_policy/rate_delay to do. The new default is still good hygiene (it matters if a future lonboard release removes its own throttle, or for rapid programmatic .widget.view_state = ... writes), but don’t expect a visibly different fire count from rate_delay=0 on lonboard the way you would on plotly or ipydatagrid, whose underlying streams really are that chatty.

A few accessors still have no declared rate policy at all, where rate_policy/rate_delay do nothing: mols2grid’s accessors, ipyvolume’s camera(), and k3d/pythreejs’s camera(). If your accessor is on this list and a downstream recompute is expensive enough to matter, debounce the expensive step yourself with reactive.debounce() (see Reacting to widgets).

Rate limits matter most when one gesture arrives as a burst of messages, because the cost multiplies. ipycytoscape is the clearest case: each node is its own widget, so box-selecting N nodes sends N messages, and an app that loops reactive_read(node, "selected") over every node redoes that loop on each one, about N² work for a single gesture – that pattern took several seconds to catch up after selecting 1,000 nodes and fell minutes behind at 3,000. Collecting the burst into one value, which is what selected_nodes() does, kept up in a second or two. The same applies to any widget that reports one gesture as many trait changes.

For contrast, accessors that do declare a default policy and visibly respond to it: plotly’s selecting() and ipydatagrid’s selected() (both cited above), mosaic’s params() (debounced fires far less often than rate_delay=0 for one brush drag), and ipyaladin’s drag-to-rotate gesture (debounced fires noticeably fewer times than raw updates).

5. Bundle size and first load

Every shinywidgets app pays a shared static framework cost on first load – Shiny’s own JS/CSS, Bootstrap, jQuery, bslib components, and shinywidgets’ own ipywidget-output-binding loader (dominated by one ~3.6 MB libembed-amd.js file) – regardless of which widget you use. Four completely different renderers (plotly, jscatter, perspective, k3d) each loaded about 5 MB of static HTTP assets before a single widget-specific byte arrived. On top of that shared baseline, each renderer adds its own JS (or WASM) bundle, measured here with a tiny, near-empty widget so the renderer’s fixed cost isn’t confused with its data cost (that’s Section 2’s job):

Renderer Renderer-specific bytes Total first load
matplotlib ~0.2 MB ~5.3 MB
itables ~0.8 MB ~5.9 MB
ipyleaflet ~1.3 MB (+ ~0.5 MB basemap tiles, viewport-dependent) ~6.3 MB
jscatter ~2.3 MB ~7.4 MB
k3d ~4.6 MB ~9.6 MB
plotly ~5.4 MB ~10.4 MB
perspective ~6.5 MB ~11.5 MB
lonboard ~10 MB (incl. a ~5.3 MB parquet-wasm fetch from a CDN) ~15 MB

examples/14_bundle_matplotlib.py, examples/12_bundle_itables.py, examples/11_bundle_ipyleaflet.py, examples/05_bigdata_jscatter.py (run at PERF_N=100), examples/13_bundle_k3d.py, examples/04_bigdata_plotly.py (run at PERF_N=100), examples/07_bigdata_perspective.py (run at PERF_N=100), examples/06_bigdata_lonboard.py (run at PERF_N=100)

import matplotlib.pyplot as plt
import numpy as np
from shiny.express import ui
from shinywidgets import render_matplotlib

ui.page_opts(title="bundle: matplotlib", fillable=True)


@render_matplotlib
def plot():
    fig, ax = plt.subplots()
    rng = np.random.default_rng(42)
    ax.scatter(rng.normal(size=50), rng.normal(size=50))
    return fig

These numbers assume the local, already-installed copy of every renderer’s JS (shinywidgets[<extra>] installs the nbextension data _dependencies.py looks for first). If a deploy is missing an extra and falls back to the CDN (unpkg.com), treat that as strictly more bytes and more latency than the numbers above, not less.

What this means in practice

Cold start – the very first thing a brand-new browser (no cache) loads from your app – costs somewhere between about 5 MB (matplotlib: a static image, essentially no interactive JS) and about 15 MB (lonboard: a full WebGL mapping + GeoArrow stack) before any of your actual data arrives. The ~5 MB shared framework cost is fixed and not something a widget choice changes; the renderer-specific column is the one your choice of library controls. If first-load latency on a slow connection matters more than feature breadth, that’s a real argument for itables or a plain plot over perspective or lonboard for a given page – and it’s additive: a page with three different heavy renderers pays all three renderer-specific costs once each, on top of one shared baseline.

Pitfalls and a checklist

  • A heavy downstream recompute driven by a continuously-streaming accessor with no rate limit can stall the browser badly enough to break the gesture that’s feeding it – a full figure rebuild on every tick of a drag is the classic case. For whatever’s still on the no-op rate-limiting list (Section 4): update a companion view in place on each tick instead of rebuilding it from scratch, regardless of how often the accessor fires.
  • Re-rendering an anywidget-based widget resends its entire JS bundle, every time, not just its data (Section 1). If a change can be expressed as a trait mutation on the existing widget, prefer that – but verify what the trait mutation actually sends (the ipyleaflet style case in Section 1 is the cautionary tale: not every “in-place” update is cheap).
  • shared_lifetime() built directly in a Shiny Express script’s top level is rebuilt once per session, silently defeating both the memory savings in Section 3 and the cross-session mirroring it’s meant to provide – see Updating in place for the worked repro. Put it in a sibling globals.py, as every example in Section 3 does.
  • Keep a shared_lifetime() cache module in its own subdirectory. Shiny Express imports a directory’s globals.py before running any app in it, so every app there builds the shared widget and holds it in memory, even apps that never show it. (Sessions are only sent the shared widgets they display.)
  • A million-point scatter plot is not automatically a bad idea, but budget for both bytes and client-side render time (Section 2) – and for genuinely tabular data (sort/filter/browse, not a 2D point cloud), perspective’s virtualized architecture sidesteps the scaling problem entirely.
  • Bundle size is additive across renderers on one page, and paid once per browser, not once per server. Five different heavy widgets on one dashboard means five renderer-specific bundles for every new visitor, on top of the one shared framework cost (Section 5).
  • Checklist before shipping a widget-heavy page:
    1. Does every update to this widget need to re-render, or can an effect mutate a trait in place? (Section 1)
    2. At your expected data size, have you actually measured the renderer’s payload and render time, or are you assuming? (Section 2)
    3. If this widget is shown to many concurrent users and the data is the same for all of them, is it a shared_lifetime() candidate? (Section 3)
    4. Does the accessor you’re reading in a hot path declare a default rate policy, and can one gesture send it a burst of changes? If so, are you reading an accessor that collects the burst, or debouncing the expensive part yourself? (Section 4)
    5. How many renderer-specific bundles does one page load, and does that match your target audience’s connection? (Section 5)

Where to go next

  • Reacting to widgets: the conceptual model this article’s measurements build on – accessor kinds, re-fire/clearing semantics, the three lifetimes, writing back without looping.
  • Linked views: coordinating multiple widgets through accessors (a different concern from this page’s single-widget performance, but the same reactive.effect + in-place-update idiom).
  • Per-widget guides with their own measured performance notes: pyvista (the trame-pyvista 0.2.3 -> 0.3.4 payload story), keplergl (playback rate limiting), ipydatagrid (selected()’s default debounce vs. an un-rate-limited reactive_read(), and the in-place-update pattern for a heavy downstream recompute), itables (maxBytes downsampling for large tables), plotly, lonboard, jscatter, perspective.