Skip to content

Skip viewport requests that cannot change the result: span-covered pans and wheel bursts #34

Open

Description

@jvdd

Client-side optimization, not scheduled. Investigated 2026-09-06 on feat/geo-hist2d-ooc after the snapped histogram grids landed.

Problem

Every relayout on a recompute axis sends a viewport request. A pan or a zoom-out at full extent, where the viewport still covers the whole data domain, re-aggregates and re-sends a result that cannot differ from the unzoomed one. On the Plotly path a scroll-wheel zoom fires one request per relayout, with no debounce.

What one request costs, resident frame of 2M rows, warm, median of 5 through FlexEngine.process:

trace aggregate
hist1d 3.0 ms
line, 1000 points 2.3 ms
hist2d 100 x 100 7.2 ms

A hist2d 100 x 100 delta is 808 KB of JSON, 47 KB gzipped, and costs 13 to 19 ms to serialize in the server handler. The wire is the larger half. Geo hist2d ships GeoJSON polygons per non-empty cell, so it is heavier per cell.

There is also a visible artifact today: the unzoomed grid spans exactly the domain, while a zoomed grid is snapped to a lattice of width span / bins anchored at 0. The first pan at full extent therefore re-bins onto a different lattice, and every bar shifts and widens by the Plotly autorange padding. Skipping that request keeps the unzoomed grid on screen.

What the client knows today

  • handleRelayout (flexviz/adapters/js/plotly/events.js) persists the viewport on every relayout and gates the request with fvNeedsFetch on recompute_axes (flexviz/adapters/js/runtime/state.js).
  • The client never records the span the displayed data was computed over.
  • The client does not know the data domain. Histogram centers span it minus half a bin at each end, a line's downsampled x extent is close but not guaranteed, geo ships polygons.
  • The server resolves the domain per request in _resolve_domains (flexviz/engine.py) and TraceDelta (flexviz/events.py) has room for one more field.
  • Traces without recompute axes (bar, pie, box, treemap, corr heatmap) already skip on both sides. Dashboards never link axes across figures, so one figure's pan never re-aggregates a sibling.

Proposed rules, ranked

  1. Span-covered skip. Per recompute axis: the new viewport span is at least the domain span, and the displayed data is the unzoomed one. Then skip. Provably non-lossy: with bins cells over a span at least as wide as the domain, the server can only return the same or a coarser grid over the same or fewer rows. Plotly keeps the axis range the user set; no clipping. Covers hist1d, hist2d, geo hist2d and line. Needs domain: {axis: [lo, hi]} on TraceDelta, filled from _resolve_domains, and one boolean per figure and axis on the client. About 45 lines: events.py +2, engine.py +15, runtime/delta.js +5, runtime/state.js +20, plotly/events.js +3, plus an engine test, a spec round-trip test and one browser test.
  2. Wheel debounce. Not a skip: one 80 to 120 ms timer around postDashboardUpdate in handleRelayout with an in-flight guard. About 15 lines. Removes more requests per wheel gesture than rule 1.

Not proposed: a margin prefetch so pans inside an already fetched span skip while zoomed. It needs a per-figure and axis fetched-span store, a margin factor and clipping on render, about 120 lines, and the margin widens the lattice the user asked for. The measured saving per pan does not justify it.

Correctness notes

  • An active selection does not invalidate the skip: the overlay bg and fg layers were fetched under the current viewport and stay on one grid.
  • The init cache stays disqualified while any viewport is set, unchanged.
  • No push channel exists, so a source re-registration already leaves the browser stale; the skip adds no new class of staleness.
  • force_update is set only by selection and click paths, which never take the viewport gate.
  • window.flexvizState() returns the persisted viewport, so agent readback stays exact.

Separate defect found on the way

The geo histogram fires a second full request right after load, when the map settles and emits its derived coordinates. Not a skip rule; worth its own fix.

Activity

  1. added
    enhancement
    on Sep 6, 2026
  2. jvdd commented on Sep 6, 2026

    @jvdd
    ContributorAuthor

    Two nuances from the same investigation, for completeness:

    • Zoom-out while zoomed that stays inside an already fetched span. Same shape as the rejected margin prefetch: it needs the per-figure and axis fetched-span store and clipping on render. Not proposed for the same reason. If the margin approach is ever taken, this case comes with it for free.
    • An explicit grid on the delta. The span-covered skip reads the span the displayed data was computed over. Today the client can only infer it from the bin centers. A small additive grid field on TraceDelta (edges and bin count per axis, alongside the proposed domain) makes that explicit and keeps the snap rule in one place on the server. See notes/2026-09-06-snapped-grid-client-vs-server.md for why the snap stays server-side.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions