graph.html is hard to move on a dense graph
Problem
graph.html is the page a person opens after graphify extract and graphify cluster-only. On a dense graph it is unpleasant to move around.
Upstream v8 makes a drag or a zoom feel lighter by setting hideEdgesOnDrag and hideEdgesOnZoom. The edges disappear while the pointer is down and come back when it is released. That is a different picture from the graph at rest. On top of that, the nodes change size while the view moves, a hover in a dense cluster stalls, and opening the same graph again re-runs the force solver from scratch.
The aim is a page that stays the graph people already have, and stays that graph while it is moving.
Constraints
These were the rules for the change. They are why the patch looks the way it does.
- Do not hide edges during a drag, a pan, or a zoom. The frame in motion has to be the frame at rest.
- Do not change a node's size because the pointer went down or the camera moved.
- Hover highlights only the edge or the node under the pointer. It does not dim the rest of the graph. Dimming is a click.
- The sidebar still classifies communities by colour and by name. The name box filters that list. It is not a second list.
- A small graph stays on vis-network's own drawing. The extra path is only for a drawn graph over 800 nodes, and arrowheads wait until hover only over 1,500 edges.
- Graphs over the existing 5,000 node limit still become the community summary. This does not raise that limit.
- No new renderer, no new dependency, no change to extraction, clustering, or
graph.json.
Why this is not a WebGL renderer
vis-network 9.1.6 draws on a 2D canvas. It has no WebGL mode. A replacement was tried: sigma.js on the same graph (1,886 nodes, 3,876 edges), on a real GPU, not software WebGL. Pan went from about 5 fps on the shipped page to about 90–110 fps.
That spike was rejected. The picture was not the graph this page already is. Community colours, the smooth curves, the sidebar, hover, and click would all have been reimplemented, and the result still looked like a different product. Speed that changes the graph people open is not the goal.
The cost was also not "canvas cannot do this". It was specific work on the canvas path:
- one
stroke()per edge per frame (about 3,876 strokes, ~30 ms, on that graph) - one border stroke per node per frame
network.setOptions()during a gesture, which forces a full synchronous redraw- a hover that wrote the edge DataSet and pulled a hub's edges back out of any batch
- the canvas waiting on the compositor before the next frame could be presented (interaction-to-next-paint about 166 ms, down to about 55 ms once the context is
desynchronized: true)
All of that can be fixed inside the existing page. WebGL stays available later if a graph is so large that even the on-screen strokes cannot hold a frame rate. It is not required for the graphs this viewer is asked to draw, and anything over 5,000 nodes is already the community summary.
What changed
One runtime file, graphify/exporters/html.py. export html, cluster-only, and watch all call to_html there, so every new graph.html gets this. Against current v8 the file is +1,192 / −81. The behaviour tests are a new file, tests/test_html_perf_levers.py.
What every graph gets:
- The canvas context is created with
desynchronized: true. - The layout is saved in
localStorageafter the solver finishes. Opening the same graph again skips the 200-iteration solve. The positions are that graph's own positions. - The community list has a colour strip and a name filter. "All" resets it.
- Hover is on. It highlights the edge under the pointer (and that edge's arrowhead) or the node under the pointer. It does not dim neighbours, and hovering a node does not fan arrowheads onto every incident edge. That fan-out was the stall in a dense cluster. Click still focuses and dims what is not connected.
What a drawn graph over 800 nodes also gets:
- Solid edges are stroked in groups of the same colour and width, one
stroke()per group, with the same curve vis was already drawing. Dashed, selected, hovered, and arrowed edges stay on vis's own draw. - While zoomed in, if most edges are off screen, each visible edge is stroked on its own. A colour group can be hundreds of curves spanning a huge path, and stroking that whole path is what made zoomed-in panning hitch.
- Node discs keep one radius for the life of the gesture. The radius is stored on the node so a DataSet write during a drag cannot snap it back, and hover or select does not halve it.
What a graph over 1,500 edges also gets:
- Arrowheads are not drawn on every edge every frame. Direction is still there: hover the edge and its arrowhead is drawn. Below the threshold the arrowheads stay as they are today.
What this does not include
The branch this was developed on also has lab notes, screenshots, a sigma.js prototype, and older unrelated commits. None of that is in the patch. The pull request is the exporter and the tests that pin it.
How it was checked
tests/test_html_perf_levers.py pins the behaviour above: edges stay in the page during a gesture, the edge batch groups by colour and width and leaves dashes to vis, off-screen curves are dropped, hover never dims, the families panel has one row per community and a name filter, node size is not rewritten on a gesture, and the desynchronized patch is emitted before the vis script. The existing to_html tests (search, legend, theme, script breakout, showInfo) still apply.
By hand, the same folder was built the way a person builds a graph, once with upstream v8 and once with this file:
- A code graph of 918 nodes and about 2,400 edges (under the 5,000 cap, over the 800 node threshold, so the zoom path is in the page). At rest the two pages are the same kind of graph. v8 hides edges while dragging and the sidebar says "Select All". This page keeps the edges and the sidebar has the colour strip and the name filter.
- A larger repo that goes over 5,000 nodes. Both versions draw the community summary, which is under 800 nodes, so that page has the sidebar and the saved layout, and does not include the zoom culling. That is the existing node limit, not a new one.
- On a 1,597 node / 3,651 edge graph, the first open was not faster (10.7 s against 8.1 s for v8). The second open was 0.7 s against 9.7 s, because the solver result had been saved.
Before and after, the same graph, upstream v8 beside this branch. The recording is the drag and the zoom, not a still of the first frame.
https://youtu.be/pSgp00Xr-jA
Pull request
The patch is #4723, on perf/html-render-qol, based on current v8, commit d67b1022.
Thanks for opening this issue, @nothariharan. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
Draft pull request: https://github.com/Graphify-Labs/graphify/pull/4723
The before/after recording of the same graph will be added on this issue.
Before and after on the same graph, upstream v8 beside this branch. It is the drag and the zoom.
https://youtu.be/pSgp00Xr-jA