Skip to content

Draw the pick pass on demand - #3

Draft
katosh wants to merge 7 commits into
masterfrom
pick-on-demand
Draft

katosh wants to merge 7 commits into
masterfrom
pick-on-demand

Conversation

@katosh

@katosh katosh commented Dec 5, 2026 •

Copy link
Copy Markdown

The scene draws all its objects into the pick buffers in each frame that moves the camera. Only pointer events with no button down query those buffers. So each frame of a rotation pays for a pass that nothing reads. In plotly.js with 2 million glyph markers, a rotation frame takes 31.2 ms against 45.2 ms, with 10 draw calls against 20.

Bar chart: 20 draw calls for each rotation frame before and 10 after, 10.5 for each pointer move before and 0 to 1 after
Draw calls of a plotly.js scene for each rotation frame and each pointer move, before and after. Ten traces, 100,000 glyph markers, thus 10 calls draw the scene one time.

This PR draws the pass when a pointer event queries it. plotly.js uses the change settylab/plotly.js#8.

  • pickMode: 'lazy' is the new default. redraw starts a timer and draws no pass. ensurePick() draws the pass and reads it back at once. It waits for the frame of a change, and for 1 ms after the first frame of new objects, as the read-back in end() did. The mouse handler calls ensurePick() before a query. The timer calls it pickIdleDelay ms (120) after the last frame, if no button is down.
  • pickMode: 'eager' gives the previous behavior
  • The scene draws no pass if all objects have noPick settylab/gl-scatter3d#5
  • pickOnPress limits queries to a press of the primary button
  • A hover that cannot change the picture calls onrender and draws no frame. That is the case with the spikes off and a highlightScale of 1.
  • After a pass on demand, the objects get the pixel ratio of the scene back, because the mesh pick reads it
  • pickStats.draws counts the passes, for tests

The change needs sync() from gl-select-static settylab/gl-select-static#1. This branch does not change package.json.

This package has no automated tests. The plotly.js bundle built from this branch is byte-identical to the bundle in the plotly.js PR. The 3D suites of plotly.js and 10 new specs pass on that bundle, with the same pixels and events as before.

At 50M disc markers in plotly.js with visible axes, a rotation step took 250 ms against 272 ms, with 0 pick draws against 400. With hidden axes it took 207 ms against 260 ms, and 259 ms with pickMode: 'eager'. A hover gains only with the spikes off: with visible axes it took 99.6 ms against 99.2 ms.

The release after a rotation costs more, because the handler draws the pass and reads it back. With visible axes it took 265 ms against 181 ms. These are medians of 9 releases, with ranges of 202 to 445 ms and 138 to 229 ms. These times compare the combined plotly.js branch pr/all with its typed-position branch, one run each.

If you prefer 'eager' as the default, we will change it. We can also split this PR. Thank you for your time.

The scene drew every pickable object into the pick buffers, and read them
back, in every frame in which the camera moved, although the buffers are
only queried by pointer events with no button held.

- pickMode 'lazy' (default): draw the pass when a pointer event is about
  to query it, or pickIdleDelay ms after the last frame that changed it
  (never while a button is held), and read it back at once. 'eager' is
  the previous behaviour.
- Draw no pass when no object can be picked (objects flagged noPick).
- pickOnPress: query only when the main button goes down.
- A hover that changes nothing in the picture (spikes off, highlightScale
  1) calls onrender without a frame.

Needs gl-select-static with sync().
A pointer event between scene.add and the next frame drew the pick pass with the new object, so the scene gave a hit for an object that no frame had drawn, with the camera and bounds of the frame before. The pass in the frame never did that. ensurePick now returns while the scene waits for a frame.
A new select buffer takes its memory from the pool and does not fill it. With the pick pass on demand, a pointer event can come before the first pass, for example while a change waits for its frame. The query then read the picture of an earlier scene and could give a hit. The scene now queries the buffers only after a pass has drawn all of them.
…e frame pass did

The pick pass of a frame was read back 1 ms later, so a pointer event that came right after a frame found the picture of the frame before, and nothing after the first frame of a scene. The pass on demand answered such an event at once. A pointer that rests on a scene when its canvas appears then got a hover label that it did not get before, and later events at the same place are not reported, so the label stayed. The pass on demand now waits the same 1 ms.
A scene that draws frame after frame started the timer again before it ran out when the page was busy, so the wait could last as long as the frames. One timer runs at a time now.
The wait started after every frame that left the pick buffers out of date. A scene that draws frame after frame, as it does while the camera settles after a plot, then refused a pass on demand for 1 ms or more in each frame, and a pointer event in that time found nothing. The frame pass never did that: it gave the picture of the frame before. Only the first frame after scene.add or scene.remove starts the wait now.
…ge of the objects

plotly draws an empty first frame and then the frame with the traces in one task. The wait ran from the first of the two, so it could end before the read-back of the second would have. It runs from the last such frame now; only a change of the objects starts it, so frames of a moving camera cannot hold 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