Skip to content

perf(adapters): resolve linked-hover bins from the edge triples by arithmetic - #119

Merged
jvdd merged 3 commits into
mainfrom
perf/hover-bin-arithmetic
Sep 29, 2026
Merged

jvdd merged 3 commits into
mainfrom
perf/hover-bin-arithmetic

Conversation

@jvdd

@jvdd jvdd commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #38.

Change

  • The client keeps the server's [lo, step, n] edge triples per trace uid (hoverEdgesByTraceUid, renamed from hoverCellsByTraceUid because it holds triples now). _hoverBoundsFromEdges and _rebuildHoverCells are deleted, and binned traces set no customdata.
  • binAt (runtime/hover.js) finds a bin with the kernel's rule: floor((v - lo) / step + 1e-9), with the top edge closed. planHoverVisuals uses it instead of the linear scans over cells, in axis mode and in cell mode.
  • A value outside the grid gets no bin. The issue proposed a clamp to [0, n - 1], but the server never counts a row outside the grid, and a clamp would light up an edge bin for it.
  • The source cell of a histogram2d hover comes from pt.pointIndex ([row, col]) and the triples, not from pt.x/pt.y: on a date axis Plotly reports pt.x as a date string.
  • Date axis in axis mode: a hovered point on a date axis now reaches the bin lookup and the linked guides as epoch-ms. hoverDataValue (plotly/hover.js) converts Plotly's date string with the axis's own d2c. Before, the string gave NaN, so linked hover from a date axis drew no guide and no band (on main too).
  • Architecture.md and three stale comments (runtime/cube.js, trace/hist.py, trace/hist2d.py) describe the new contract.

Not changed: geo traces still build one GeoJSON rectangle per non-empty cell, because the choroplethmap needs them to draw. Geo is not a hover target (see the comment on #38).

Impact

Measured in headless Chromium, 7 fresh pages per case, median (script and raw results kept outside the repo):

2 x histogram2d 1000 x 1000 (2M rows) main this PR
JS heap after init, whole page 258.4 MiB 32.6 MiB
Delta apply, per figure 165.6 ms 133.6 ms
Trace build 34.5 ms < 0.01 ms
Hover event, full path 6866 µs 12.5 µs

A 200-bin histogram shows no meaningful change (heap 9.56 vs 9.54 MiB, hover 16.5 vs 11.5 µs).

Correctness:

  • On a numeric axis, a value exactly on an inner bin edge, or the maximum, now lights up the bin the server counted it in. On main, 0.3 on a 0.1-wide grid lit up the lower bin, and the maximum of a histogram2d got no band.
  • Linked hover from a date-axis source now draws the guide on a linked line and the band on a linked histogram.

Related: #128 (the cube live brush draws temporal histogram targets in the physical unit), found in this review.

Tests

  • New test_hover_lookup_puts_edge_values_in_the_server_bin (a histogram and a histogram2d target): the expected bin comes from the server's own counts. Fails on main.
  • New test_temporal_histogram2d_source_hover_links_the_cell: a real mouse hover on a date-axis histogram2d source links the right cell. It fails if the source bounds come from pt.x.
  • New test_mouse_hover_on_a_date_axis_links_guide_and_band: a real mouse hover on a date-axis line source; the guide and the band land on pixels from an independent UTC conversion of the hovered date. Fails before the hoverDataValue fix (no guide, no band).
  • TestBinEdgeTripleBrowser now checks that the edges map holds the triples and that binned traces have no customdata. The histogram2d test uses a real mouse hover.
  • pytest tests flexviz_polars/tests: 2427 passed, 2 skipped.
  • pytest -m browser tests: 344 passed, 16 skipped.

@codspeed

codspeed Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing perf/hover-bin-arithmetic (8df5996) with main (1ebe415)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8df5996) during the generation of this report, so 1ebe415 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@jvdd
jvdd force-pushed the perf/hover-bin-arithmetic branch from 1d3aa99 to 8df5996 Compare September 29, 2026 08:31
@jvdd
jvdd merged commit eb6976d into main Sep 29, 2026
7 checks passed
@jvdd
jvdd deleted the perf/hover-bin-arithmetic branch September 29, 2026 08:32
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.

Linked hover: look up the bin by arithmetic instead of one object per cell

1 participant