Description
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 withfvNeedsFetchonrecompute_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) andTraceDelta(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
- 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
binscells 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. Needsdomain: {axis: [lo, hi]}onTraceDelta, 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. - Wheel debounce. Not a skip: one 80 to 120 ms timer around
postDashboardUpdateinhandleRelayoutwith 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_updateis 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
jvdd commentedon Sep 6, 2026
Two nuances from the same investigation, for completeness:
gridfield onTraceDelta(edges and bin count per axis, alongside the proposeddomain) makes that explicit and keeps the snap rule in one place on the server. Seenotes/2026-09-06-snapped-grid-client-vs-server.mdfor why the snap stays server-side.