Skip to content

Use instancing for compact hexbin rendering#194

Draft
Alek99 wants to merge 1 commit into
mainfrom
agent/instanced-hexbin
Draft

Use instancing for compact hexbin rendering#194
Alek99 wants to merge 1 commit into
mainfrom
agent/instanced-hexbin

Conversation

@Alek99

@Alek99 Alek99 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Closes #175

Summary

Replaces the client-side six-way hexbin fan expansion with a dedicated instanced renderer:

  • one instance now uploads only encoded center x/y plus one color scalar
  • HEXBIN_VS generates the six triangles from gl_VertexID, using the same ring as the Python renderer
  • the existing mesh fragment shader remains responsible for LUT, alpha, and barycentric edge coverage
  • VAO, retained-payload rebuild, context restore, and resource cleanup paths cover the new program and compact buffers
  • the wire contract is unchanged: centers plus one scalar per occupied cell

Hexbin remains intentionally non-pickable, so hover behavior is unchanged. Nonlinear and reversed axes, offset/scale metadata, continuous and categorical color, colorbars, and retained-payload GL reconstruction are covered.

Performance evidence

Fresh Chromium/SwiftShader benchmark, grid size 256, 66,049 occupied cells, 9 repetitions:

metric untouched main this PR
resident vertex-attribute bytes 11,096,232 792,588
build/upload median 3.2 ms 0.1 ms
build/upload p95 5.2 ms 0.3 ms
draw median 0.3 ms 0.2 ms
draw p95 0.4 ms 0.4 ms

That is an exact 14× / 92.86% resident-buffer reduction. Both implementations rendered 4,528 nonblank pixels with pixel hash 3904178501 and GL error 0.

An independent review reran the same comparison at 16,641 occupied cells:

  • 2,795,688 → 199,692 bytes (also exact 14×)
  • build/upload median/p95: 0.8/1.1 → 0.1/0.2 ms
  • both paths: 4,618 nonblank pixels, hash 3001618805, GL error 0

Verification

  • focused hexbin/browser/plot/colorbar coverage: 5 passed
  • real Chromium cases include linear axes and log/reversed axes, exact buffer sizing, the 18-vertex instanced draw, pixel parity before/after zoom and retained-payload GL rebuild, old-buffer deletion, shader replacement, and no GL errors
  • full suite: 2210 passed, 66 skipped, 1 deselected in 75.43 s; the sole deselection is the known pre-existing tests/reflex_adapter/test_assets.py::test_client_source_is_the_installed_bundle stale literal-marker assertion, reproduced on untouched main
  • node js/build.mjs --check: committed bundles fresh
  • tsc -p js/tsconfig.json --noEmit: passed
  • ruff check .: passed
  • ruff format --check .: all 343 files formatted
  • git diff --check: passed

A reproducible benchmark is committed as benchmarks/bench_hexbin_client.py.

@codspeed-hq

codspeed-hq Bot commented Jul 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 97 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing agent/instanced-hexbin (15c9f10) with main (2a7d898)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR moves hexbin fan generation from CPU-expanded buffers into an instanced WebGL renderer. The main changes are:

  • Adds a vertex shader that generates each cell’s six triangles from gl_VertexID.
  • Uploads one encoded center and color scalar per occupied cell.
  • Updates draw dispatch, GPU reconstruction, cleanup, and generated browser bundles.
  • Adds browser tests, a focused benchmark, and renderer contract documentation.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the hexbin client instancing test with Playwright, and the run completed with 2 passed in 3.23s.
  • Compared the poster frames before and after the change; the frames are pixel-identical, and the after recording exercises retained-payload GL teardown and rebuild.
  • Reviewed the full artifact set (logs, videos, and images) to support validating the test outcomes and GL teardown behavior.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
js/src/40_gl.ts Adds the instanced hexbin vertex shader and reuses the mesh fragment shader for color, opacity, and edge coverage.
js/src/50_chartview.ts Replaces expanded triangle attributes with compact center buffers and adds dedicated hexbin program, VAO, and draw handling.
js/src/55_marks.ts Routes hexbin marks through the new instanced draw path while retaining axis and theme refresh behavior.
tests/test_hexbin_client_instancing.py Covers compact buffer sizing, instanced drawing, nonlinear axes, zoom, resource teardown, and retained-payload reconstruction.
benchmarks/bench_hexbin_client.py Adds a browser benchmark for upload time, synchronized drawing, resident buffer size, and rendered output.
python/xy/static/index.js Updates the shipped ESM bundle with the instanced hexbin renderer.
python/xy/static/standalone.js Updates the shipped standalone bundle with the instanced hexbin renderer.

Reviews (1): Last reviewed commit: "Use instancing for compact hexbin render..." | Re-trigger Greptile

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.

Hexbin client fan expansion: 42 floats/cell CPU+GPU where instancing needs 3

1 participant