Skip to content

Reduce plotting slider payload for faster figure load#2285

Open
Neal006 wants to merge 1 commit into
google-deepmind:mainfrom
Neal006:perf/plotly-slider-payload
Open

Reduce plotting slider payload for faster figure load#2285
Neal006 wants to merge 1 commit into
google-deepmind:mainfrom
Neal006:perf/plotly-slider-payload

Conversation

@Neal006

@Neal006 Neal006 commented Jul 14, 2026

Copy link
Copy Markdown

Fixes part of the slider payload bloat described in #553.

Problem

_get_slider_steps() re-sent the full (static) x-array for every spatial
trace on every slider step, and encoded the timestamp indicator as a
per-step trace update instead of a lightweight shape move. Neither the
x-grid nor the vline's y-extent changes between steps — only trace y-values
and the vline's x-position do.

Fix

  • Timestamp indicator is now a layout.shape (moved via relayout) instead
    of a full trace re-sent on every step.
  • Slider steps use Plotly's update method with separate restyle (y only)
    and relayout (shapes[i].x0/x1) payloads — x arrays are no longer
    duplicated per step.
  • updatemenus mode-switch buttons now merge the relayout keys into their
    existing step-0 args instead of duplicating them.

Measured (rampup reference dataset, min of 5 runs)

Metric Before After Δ
Figure JSON size 1.81 MB 1.31 MB −28%
to_json() time 0.089s 0.059s −34%
Figure build time 0.851s 0.824s −3% (build is dominated by .nc load, not slider assembly — see note below)

Build time is largely unaffected because it's dominated by data loading and
trace construction, not slider-step serialization. The measured win is in
payload size and serialize time, which is what actually affects load and
parse time client-side (browser fetch/parse/hold of the HTML figure).

This is one isolated speedup, per your request. A second, larger win is
still on the table: the updatemenus buttons currently embed a full copy
of both slider-mode step lists (linear time vs. simulation steps), so the
step data is stored ~2x beyond what's in this PR. That's a design choice
(which mode's steps live in the button vs. get rebuilt) I'd like input on
before touching it — happy to open a follow-up issue/PR once we agree on
approach.

Tests

Added SliderPayloadTest in plotruns_lib_test.py (4 cases): steps carry
no x payload, timestamp indicator moves via shape relayout, timestamp
indicator is a shape not a trace, mode buttons still switch slider steps.
Full plotting suite: 236/236 passing.

@google-cla

google-cla Bot commented Jul 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Slider steps re-sent the static rho-grid x-arrays for every spatial
trace at every timestep, and timestamp vlines were traces whose x/y
were restyled per step. x-arrays are now set once on the traces, and
the vlines are layout shapes moved via the relayout part of the
slider 'update' method.

Figure JSON size: -31% on a 106-step basic_config run (4.2->2.9 MB),
-28% on iterhybrid_rampup. No visual change.

Addresses part of google-deepmind#553.
@Neal006

Neal006 commented Jul 18, 2026

Copy link
Copy Markdown
Author

@jcitrin , just checking up on updates regarding the PR approval. If there are any changes that you need me to do, I'm happy to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant