Skip to content

[DO NOT MERGE] feat: Large and translucent point clouds in scatter3d and scattergl (overview draft) - #11

Draft
katosh wants to merge 63 commits into
mainfrom
pr/all
Draft

katosh wants to merge 63 commits into
mainfrom
pr/all

Conversation

@katosh

@katosh katosh commented Dec 5, 2026 •

Copy link
Copy Markdown

Description

This draft is an overview. Do not merge it. Review and merge the pull requests in the table, and only the ones that you want.

AnnZarro is an open viewer for single-cell data. It draws 1 million to 100 million points with plotly.js. At that size, plotly.js reaches three limits:

Key results

Scenario Upstream main This branch (all ten PRs) PRs that give it
3D, 2M points: open about 3,650 ms (median of four runs) 183 ms #4, #7
3D, 2M points: rotation frame 45.2 ms 7.9 ms #4, #8
3D, 2M points: recolor of one trace about 3,240 ms (median of four runs) 23 ms #4, #7
3D, 2M points: GPU buffers 8,320 MB 32 MB #4, #7
3D, 20M points in ten traces does not load: RangeError: Invalid typed array length: 624000000 open 426 ms, rotation frame 34.7 ms #4, #7, #8
3D, 50M points does not load: RangeError: Invalid typed array length: 1560000000 open 845 ms, rotation frame 84.9 ms, 800 MB of GPU buffers #4, #7, #8
3D, 100M points fails: already at 50M (measured) open 1,498 ms, rotation frame 174 ms, 1,600 MB of GPU buffers, hover works #4, #7, #8
3D, 500M points fails: already at 50M (measured) open 6,633 ms, rotation frame 910 ms, 6,000 MB of GPU buffers, no hover at this size #4, #7, #8
2D, 20M points: open 3,918 ms 332 ms #9
2D, 20M points: recolor of one trace 3,778 ms 110 ms #9
2D, 20M points: GPU buffers per point 17 bytes 8 bytes #9
2D, 50M points opens in 11.7 s, then the browser tab crashes at the first pan open 733 ms. With layout.lod (#10 alone): first frame 245 ms, full picture 885 ms, pan frame 5.4 ms #9, #10
Translucent 3D, 200k points, opacity 0.5: mean error against a sorted render 29.5 of 255 levels 2.2 of 255 levels (#5 alone, scene.oit: 'auto') #5

The timings ran on the strict bundle of fd8cfbb56. Later commits change only the pick pass after an add or a remove, a fallback for a missing timer extension, and tests.

Four line charts: the time to open and the GPU buffers against the number of points, for scatter3d and scattergl. Upstream ends with a red X where the plot fails
Time to the first frame and GPU buffers against the number of points. The red X marks where upstream main stops. In 3D, that is a RangeError from 2M points per trace. In 2D, the tab crashes at 50M points. With #4 alone, the tab crashes at 100M points. Above 16.7M points in one trace, a trace keeps no pick ids, thus it has no hover and holds 12 bytes per point, not 16.

Conditions: Apple M3 Max, headless Chromium on ANGLE Metal, 1200 x 800 px. Each plot holds ten traces of opaque markers of size 3 with Float32Array input, and hover is off in 2D. Each number is one run, unless the cell says median. In 3D, this branch draws discs (scene.markerrender: 'auto'), and upstream draws its default glyph markers. The 2D pairs are strict bundles from one builder. Upstream is plotly.js main (df22b38).

This branch holds ten pull requests that remove these limits. Each one is opt-in or moves no pixel. We can rework, combine, split, or drop each one. Thank you for your time.

Changes

Each row links a review pull request in our fork. For each one that you want, we open one short issue and one pull request here that closes it.

PR Change Effect Measured, the PR alone against its base Needs
#1 One WebGL context per scattergl graph The graph creates the second context when a selection starts 2 contexts to 1 per graph
#2 No recalc under scaleanchor A pan or a zoom on constrained axes with fixed ranges recalculates no scattergl trace Pan step at 5M points: 908 ms to 72 ms
#3 No outline vertices without an outline A circle marker without an outline uses fewer vertices 104 to 60 vertices per marker
#4 Circle markers as discs, scene.markerrender One vertex per marker. The outline gets the width that marker.line.width sets (plotly#3796). Vertex buffers at 1M markers: 4,160 MB to 36 MB. Open at 1M markers: about 1,940 ms (median of four runs) to 238 ms.
#5 Order-independent transparency, scene.oit Translucent scatter3d markers blend by depth (plotly#1267) Mean error against a sorted render, 200k points: 29.5 to 2.2 of 255 levels. Cost: a rotation frame at 1M glyph markers takes 60.3 ms, not 24.0 ms.
#6 alwaysontop for scatter3d plotly.js draws the trace last, without a depth test. Hover still works. See the image below #5
#7 Typed x, y, z for scatter3d One Float32Array per trace. An edit that keeps the positions uploads no position. Recolor at 20M markers: 1,110 ms to 85 ms, 720 MB to 0 MB. JS heap: 54 to 0.13 bytes per marker. #4
#8 Pick pass on demand A rotation frame draws no pick pass. With the axis spikes off, a hover that changes no pixel draws no frame. Rotation frame at 2M glyph markers: 45.2 ms to 31.2 ms, 20 draw calls to 10
#9 Typed x and y for scattergl Float32 data goes to the GPU one time. A recolor or a reorder uploads no point. Reorder at 20M points: 680 MB to 0 MB, 3,774 ms to 110 ms settylab/regl-scatter2d@37e6583
#10 Level of detail, layout.lod and scene.lod A thinned preview first, the full picture at rest Pan frame at 20M points: 114 ms to 5.4 ms #9 for 2D, #4 for 3D
Disc markers in the order-independent passes One gl-scatter3d commit. A scene needs the commit only if it sets scene.oit: 'auto' and scene.markerrender: 'disc' together. Carried by whichever of #4 and #5 merges second. The branch pr/disc-oit shows that state. #4 and #5

The base of a pull request is upstream main, or the pull request that it needs.

The 3D pull requests pin gl-plot3d and gl-scatter3d to fork commits in stackgl_modules/package.json. #9 and #10 pin regl-scatter2d the same way. Each package pull request opens with the plotly.js pull request that needs it. This branch pins gl-plot3d 70ff6bd, gl-scatter3d 213d696, gl-select-static 4375784 (an override) and regl-scatter2d 37e6583. Its stackgl_modules/index.js equals a clean rebuild byte for byte.

Screenshots/Videos

Conditions for each chart: Apple M3 Max, headless Chromium on ANGLE Metal, 2026-12-04, ten traces, marker size 3, 1200 x 800 px, Float32Array input. Orange is plotly.js 2.35.3. Green is upstream main. Blue is this branch (all ten PRs). In a chart of one pull request, "this branch" is that pull request alone.

A scatter3d trace of 2,000,000 points does not load (#4 and #7)

Left: an empty plot with an error box. Right: a spiral cloud of 20 million points.
Ten scatter3d traces of 2,000,000 points each. Left: upstream main draws no point, and we added the box with the error. Right: this branch with scene.markerrender: 'auto'.

A rotation of a spiral cloud of 20 million points
20 million points in ten traces on this branch. The GIF plays saved frames, thus it shows no frame rate.

Translucent markers blend in trace order (#5, plotly#1267)

Two linked rings of translucent points in rotation, before and after
Two linked rings of 10,000 points each, marker.opacity 0.2, the same markers on the two sides. Left: upstream main. Right: #5 with scene.oit: 'auto'.

On the left, the last trace covers the other trace at each crossing. The pull request uses 16 depth layers per pixel, thus the result is an approximation, not a sort.

The marker outline (#4, plotly#3796)

Two rows of four circle markers with marker.line.width 1, 2, 4 and 8. Without discs, each outline is about 1 device pixel wide. With discs, the outlines are 2, 4, 8 and 16 device pixels wide
marker.line.width 1, 2, 4 and 8 at pixel ratio 2, Chrome with ANGLE. Top: upstream main, 0.93 device pixels at each width. Bottom: #4 with scene.markerrender: 'disc', 1.91 to 15.91 device pixels.

Chrome draws each outline 1 device pixel wide today. A disc draws the width that the attribute sets.

A highlight inside a cloud (#6)

Four renders in one camera loop: markers cut or hide a black ring on the left, and the full ring shows on the right
One camera loop. On upstream main, the markers in front cut the ring, and the cut changes with the camera. In the dense cloud, the ring has 0 visible pixels in all 72 frames. With alwaysontop: true, the full ring shows in each frame.

Time for each scenario, 3D (this branch)

Six line charts of time against the number of scatter3d points
Open, rotation frame, recolor, hide and show for 100,000 to 50,000,000 scatter3d points. At opacity 0.5, the blue line also sets scene.oit: 'auto'.

The chart draws one of the four upstream runs at 2,000,000 points, which opened in 3,585 to 4,336 ms.

At opacity 0.5 with scene.oit: 'auto', a rotation frame of 1,000,000 discs takes 22.6 ms. Upstream main takes 24.4 ms for 1,000,000 glyph markers and blends in trace order. The cost grows with the count: 20,000,000 translucent discs take 420 ms for a rotation frame, against 34.7 ms opaque. A translucent rotation at that size needs the level of detail of #10.

Time for each scenario, 2D (this branch)

Five line charts of time against the number of scattergl points
Open, pan frame, recolor, reorder and hide for 1,000,000 to 50,000,000 scattergl points, hover off, no level of detail.

The chart draws a non-strict bundle of upstream main, which gave 4,316 ms to open and 4,126 ms to recolor 20,000,000 points. With 5,000,000 points and strict bundles, the open takes 117 ms against 974 ms.

Bars of time and upload for a pan step under scaleanchor, before and after
#2 alone: one pan step with yaxis.scaleanchor and fixed ranges, median of 10 steps, strict bundles.

Single pull requests against upstream main

Four line charts of the time to open, to rotate, to recolor and to hide, for three builds
#4 alone, and #4 with #7: glyphs, discs, and discs with typed positions, 100,000 to 20,000,000 markers.

Bar charts of time, uploaded megabytes and memory at 20 million scattergl points, before and after
#9 alone: 20,000,000 points in ten traces, hovermode: false, strict bundles. The chart names commit a019f22 (source identical to 2441332).

Three line charts of the time for a rotation frame, a pointer move and the open, with scene.oit off and auto
#5 alone, the cost: glyph markers at opacity 0.5, strict bundles. scene.oit: 'auto' draws 41 calls for each rotation frame, not 21.

Bytes that go to the GPU, and memory (this branch)

Bars of the megabytes that each scenario uploads
Bars of the bytes per point in the JS heap, in ArrayBuffers and in GPU buffers
Log scales. "GPU buffers" counts the bytes that the page holds through WebGL, without driver overhead. The memory excludes the input arrays.

A recolor of one scatter3d trace uploads 8,320 MB at 2,000,000 points on upstream main, and no byte on this branch. A scattergl point needs no ArrayBuffer byte, not 32.

Bars of the megabytes that open, recolor, hide and show upload, for three builds
#4 alone, and #4 with #7: bytes that go to the GPU with 1,000,000 markers, as a count.

Draw calls for a rotation frame and for a pointer move (#8)

Bars of draw calls per rotation frame and per pointer move, before and after
#8 alone: a count with ten traces and 100,000 glyph markers. Ten draw calls draw the scene one time.

Level of detail (#10)

Six line charts of time with and without level of detail, 2D and 3D
The blue lines are #10 alone. The yellow line is this branch (all ten PRs). Preset: minpoints 1,000,000, budget 1,000,000, maxstride 64, settle 150 ms. The stride is 32 at 20M points and 64 at 50M points.

With 20,000,000 scattergl points, a pan frame takes 5.4 ms against 114 ms, and the first frame comes after 134 ms against 338 ms. The full picture comes later, after 449 ms against 338 ms, because the full draw starts 150 ms after the last draw request. With 20,000,000 scatter3d points, a rotation frame takes 4.5 ms against 44.2 ms. On this branch, the first 3D frame comes after 316 ms against 1,224 ms with #10 alone. This branch has the typed positions of #7.

Translucent discs with level of detail (#4, #5 and #10 together)

One rotation drag over five translucent clouds in two panels. Without scene.lod, the picture reaches step 31 of 90 while the drag with scene.lod is complete and shows the full picture
Screencast frames in time order: one scripted rotation drag of 90 steps over 20 million discs in five clouds, without and with scene.lod. The discs have marker.opacity 0.02, and the scene sets scene.oit: 'auto'. The GIF stops at step 31 of the drag without scene.lod. The preview draws every 32nd disc with the opacity of 32 discs. Thus the preview is as dense as the full picture, with more grain. The times in this text come from separate measurement runs.

Testing

  • Each pull request has its own jasmine specs and its own pixel comparison with upstream main. Its text lists the two.
  • With each new attribute at its default, each pull request draws the same pixels as upstream main. The 3D ones compare 7 to 49 scenes, and the 2D ones 13 to 61 scenes.
  • Image baselines: we rendered 1,302 mocks of the default suite with upstream main and with this branch on one machine (macOS). None of the 1,302 images differ. We did not compare the images with the committed baselines. The CI baseline job of this pull request is the authoritative test.
  • A default of 'auto' for scene.markerrender would move about 52 baselines, thus the default is 'glyph'
  • This branch (all ten PRs) passes these jasmine suites in headless Chrome. The 3 specs that fail also fail on upstream main.
Suite Specs that pass
scatter3d 51 of 51
gl3dlayout 24 of 24
gl3d_hover_click 37 of 39
gl3d_plot_interact 44 of 45
scattergl 59 of 59
scattergl_select 20 of 20
splom 51 of 51
gl2d_plot_interact 18 of 18
plot_api 172 of 172
gl3d_lod 7 of 7
scattergl_lod 25 of 25
  • With the virtual-webgl flags of the CI, these suites give the same result, with the same failures as upstream main:
    • scatter3d 44 of 44, gl3d_hover_click 37 of 39, gl3d_plot_interact 43 of 44
    • scattergl 51 of 51, scattergl_lod 25 of 25, gl3d_lod 7 of 7
  • One scattergl spec about animation frames ran into its timeout in 1 of 8 runs on earlier states of this branch. We do not know the cause yet.
  • With each new attribute unset, this branch draws the same pixels as upstream main on a real GPU. That holds for 61 2D scenes, 14 3D glyph scenes with equal hover ids, and 49 settled 3D frames. The 14 pointer sequences and the scene bounds are equal too.
  • Four specs exist only on this branch, because each needs two pull requests:
    • scene.oit with disc markers
    • scene.lod with the pick pass on demand
    • a typed disc trace above the range of pick ids
    • thinned translucent discs with scene.oit
  • npm run lint, npm run typecheck and npm run test-syntax pass, and npm run schema-typegen-diff-check reports no drift
  • The measurement scripts, the bundles and the raw results are available on request

Notes

Checklist

  • The linked issue has the ready-for-pr label, and it has no assignee or lists me as an assignee
  • I opened the pull request from a branch other than main in my fork
  • I selected "Allow edits from maintainers"
  • I did not edit files in dist/
  • I committed package-lock.json only for a dependency change
  • I added a file to draftlogs/ as draftlogs/README.md describes, or I will add one after the pull request opens

katosh added 30 commits December 3, 2026 22:56
The outline of a glyph marker draws only when lineWidth is above 0, but
gl-scatter3d built its vertices for every point. Count and fill them only
when lineWidth is above 0. A circle marker drops from 104 to 60 vertices.
A circle marker is a vectorized glyph mesh of 60 to 104 vertices, about
4,160 bytes in the vertex buffers. With scene.markerrender set to disc or
auto, circle and circle-open markers draw as one gl.POINTS vertex with a
round cutout in the fragment shader, with an outline ring for
marker.line.width. Other symbols, projections on the axes and sprites larger
than the point size limit keep the glyph path. The default is glyph, so
rendering does not change unless the attribute is set.

gl-scatter3d is pinned to a fork commit, and stackgl_modules/index.js is
rebuilt from it.
_relayout set flags.calc when a relayout altered the range of an axis in a constraint group. For regl traces, each zoom step then recalculated every trace and uploaded every point again.

The replot applies the constraints from the axes. Only an autorange needs the extremes of a new calc. The relayout now sets flags.plot, if every trace is a regl trace and every axis of the group has a fixed range.
…ansparency

The forks add an optional pass that blends translucent objects by depth. Nothing changes until a scene turns it on.
Rebuild stackgl_modules/index.js with npm run bundle-stackgl.
Translucent markers blend in draw order, so the last trace lies on top from every camera angle.
With scene.oit set to auto, the markers blend by depth and the draw order has no effect.
The default is off and keeps the existing pass and pixels.
The scene reports the result with getOITStatus() and the plotly_oitstatus event.
The fork skips objects with alwaysOnTop in the depth, opaque and transparent passes and draws them after the composite.
Rebuild stackgl_modules/index.js with npm run bundle-stackgl.
Points in front hide a highlighted marker inside a dense cloud.
The markers of a trace with alwaysontop true draw last, over everything else, with no depth test.
The default is false and changes no pixel. The markers stay pickable.
…anches

The scene drew its pick buffer in each frame that moved the camera. The
new gl-plot3d draws the buffer when a pointer event queries it, and draws
none if no object permits a pick. stackgl_modules/index.js is the webpack
output of the pinned commits. The pins go away when the gl-vis pull
requests merge and release.
A scatter3d trace with hoverinfo skip tells the scene that no pointer
event can select it. A scene with hovermode false queries the pick buffer
only on a button press and emits no hover events. A trace with more
points than the 24 bits of a pick id gets no hover and no click, because
its ids name other points.
The next commits pass Float32Array data to regl-scatter2d without a copy. The pinned commit holds the changes that regl-scatter2d needs for that, and a built bundle.js. regl-scatter2d builds bundle.js at publish time, so a plain git commit holds no entry file. A regl-scatter2d release replaces this pin.
calc wrote x and y of each trace to a plain Array of doubles and built an Array of point ids. regl-scatter2d then copied the positions and uploaded 16 bytes for each point. Each restyle or moveTraces repeated the copies and the upload.

For a markers-only trace on linear axes with Float32Array data, calc now passes {x, y, count, rev} to regl-scatter2d. regl-scatter2d uploads 8 bytes for each point one time. The same buffer range with the same layout.datarevision is the same data. calc reads the axis extremes from a cache and builds the point ids at the first read.

If you refill a typed array in place, set a new layout.datarevision.
calc built a point-cluster tree for each trace of 100,000 points or more, at every calc. Only hoverPoints reads the tree.

If layout.hovermode is false, or the trace has hoverinfo 'skip', the first read now builds the tree. With hover, calc builds the tree as before.
The value disc draws a glyph where a disc cannot draw the marker, and auto
is the same as disc for now. The first description left both out.
The new gl-scatter3d takes positions as one Float32Array and keeps its
position buffer when the caller sends no positions. stackgl_modules/index.js
is the webpack output of the pinned commit. The pin goes away when the
gl-vis pull request merges and releases.
A scatter3d trace made one small array for each point, also for typed x,
y, and z. Each plot call scanned the data three times and uploaded all
positions again, also for a color change of one trace.

Typed data of a trace with markers only, on linear axes, now converts to
one Float32Array. The scene scans the data one time for the bounds. A
later plot call with the same buffer ranges, scale, and
layout.datarevision sends no positions.
…aces

A scene scales its data by the extent of the visible traces. A trace that
the legend hides or shows can change that extent, and then every other
trace converts and uploads its positions again. With datascale 'all',
legendonly traces count for the scale, so the other traces keep their
positions on the GPU. The default, 'visible', does not change.
Each graph with a regl trace created two WebGL contexts. In scattergl and splom graphs, the focus layer shows only the selected points. Most graphs never select, but the browser counts the second context against its limit of about 16 for each page.

prepareRegl now creates the context of the focus layer on request, or if the graph has parcoords. scattergl sends the request when a selection drag mode starts, or when the first selection draw comes. The selected points appear on the focus layer as before.
Both branches pass the pick option to gl-scatter3d. One call of neverPicked now decides the kept positions and the pick option.
The combined branch needs every package change at one time. gl-plot3d, gl-scatter3d, and regl-scatter2d point at the all branches of the forks.
npm prepares a git dependency that has a build script. It installs the devDependencies of regl-scatter2d, which include the native gl package, and a plain npm ci fails where gl has no binary. The new pinned commit holds the same bundle.js and no build script, so npm ci needs no build.
The other draftlog files start with the dash.
…ositions

Only the combined branch drops the stored positions of such a trace, because one call decides the pick option and the kept positions.
The branch restores the description of scene.markerrender and fixes its draftlog. The combined draftlog already holds the fix.
A preview of every k-th marker had one k-th of the cover of the full picture, so faint markers all but vanished in it. A marker of alpha a that stands for k markers now gets the alpha 1 - (1 - a)^k. This is exact where the k markers cover the same pixels, and an estimate elsewhere. A marker of alpha 1 does not change.

The change is in the two packages: this commit moves the pins of regl-scatter2d and gl-scatter3d, holds the webpack output for stackgl_modules, and adds one spec for scattergl and one for scatter3d.
The branch adds two specs and moves its pins. The pins of the combined branch follow in the next commit.
gl-scatter3d and regl-scatter2d gained the opacity compensation of a level of detail preview. The stackgl bundle is rebuilt from the new pin.
The order independent passes use their own disc fragment shader. The spec shows that it links with the denser thinned draw and gives about the density of the full picture.
katosh added 13 commits December 5, 2026 01:03
With virtual-webgl, regl gets a virtual context. That context calls functions that virtual-webgl copied from WebGLRenderingContext.prototype at load, so a later spy on that prototype records nothing, and four upload specs failed in the virtual-webgl job. The specs now spy on the prototype of the context itself. Without virtual-webgl, that prototype is WebGLRenderingContext.prototype as before.
virtual-webgl returns an object with constants and no functions for an extension that it does not wrap, also when the context has no such extension. The level of detail tested only that the object exists, and then threw in the timer that draws the full picture in parts. The full picture never came. The extension now counts as missing unless createQueryEXT and getQueryObjectEXT are functions, and the plot waits with readPixels after each part.

One spec passes such an object to the scene. The spec was not run on this machine before the commit.
…before the first frame of a trace

Two specs compare a run whose hover events come from the frame with a run whose events come from the pointer handler. They waited 60 ms after each pointer event, and on a slow runner the frame came later, so the frame run lost its last events. They now wait for the frame.

The new spec sends a pointer event in the task in which newPlot resolves. It needs the gl-plot3d commit that draws no pick pass on demand before the frame that draws a change. The pin of that commit follows.
The branch counts the uploads on the context that regl uses, so that the upload specs pass with virtual-webgl.
The branch waits with readPixels when the timer query extension has no functions, as with virtual-webgl.
The pinned commit draws no pick pass on demand while a change waits for its frame, and queries no pick buffer before a pass has drawn it. Without it, a pointer event between scene.add and the next frame gave a hover label for a trace that no frame had drawn. The stackgl bundle is the webpack output for the pin.
…r the frame of a change

The pick pass on demand no longer runs before the frame that draws a change, and no query reads a pick buffer before a pass has drawn it. The stackgl bundle is rebuilt from the new pin.
The branch brings its specs for the frame of a change. The combined branch keeps its own pins and the bundle rebuilt from them.
plotly draws the first frame of a scene inside newPlot, so the event of the spec comes right after that frame, not before it. The spec text said otherwise.
The pinned commit gives a pick pass on demand 1 ms after a frame that changed the scene, as the read-back of the frame pass did. A pointer event right after the first frame of a scene finds nothing again, so a pointer that rests on a scene gets no hover label until it moves. The stackgl bundle is the webpack output for the pin.
…objects

The pinned commit gives no pick pass on demand for 1 ms after the first frame that follows scene.add or scene.remove, as the read-back of the frame pass did. A pointer that rests on a scene when it appears gets no hover label until it moves, as before. The pins of the two commits before this one made the wait too wide: it also ran after each frame of a moving camera, and hover specs failed at random. The stackgl bundle is the webpack output for the pin.
A pick pass on demand waits 1 ms after the first frame that follows a change of the objects. The frame at the end of scene.plot no longer lets a pointer event pick before that.
The branch brings its specs for a pointer event right after the first frame of a scene. The combined branch keeps its own pins and the bundle rebuilt from them.
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