Skip to content

Draw badges only for nodes in view - #2702

Open
kmcginnes wants to merge 4 commits into
mainfrom
cull-badge-overlay-pan-zoom
Open

kmcginnes wants to merge 4 commits into
mainfrom
cull-badge-overlay-pan-zoom

Conversation

@kmcginnes

Copy link
Copy Markdown
Collaborator

Summary

Panning and zooming the Graph View drops to about 13 fps at 5,000 nodes, because the badge overlay walks every node on every frame, even off-screen nodes and at zoom levels where no badge shows.

User-facing: Panning and zooming large graphs is smoother. Badges look the same.

 on(cytoscape render)
   clear the badge layer
+  if zoom band is "small"
+    return                      # badges were already hidden here
+  compute the zoom band once
   for each node
-    compute the zoom band
+    if its center is outside the viewport plus 60 units
+      skip
     if hidden or transparent
       skip
     draw its badges
-      set the font up to 4 times, measure each text
+      set the font once (twice with a title)
+      reuse cached widths and truncations per font
  • drawNodeBadges in useRenderBadges.ts holds the per-frame loop so it can be tested with headless Cytoscape.
  • drawBoxWithAdornment.ts caches text widths and truncated text per font, with a 50,000-entry limit per font.
  • Badge renderers are no longer called at small zoom, so BadgeRenderer's zoomLevel drops "small" and the two checks for it in useNodeBadges.ts are gone.

Evidence

Before: At 5,000 nodes, zoomed in close enough to show badges, a pan ran at 13.0 fps and a zoom at 23.7 fps. The overlay took about half the main thread.

After: The same pan runs at 26.4 fps and the zoom at 41.1 fps. At 2,000 nodes, a close pan goes from 41.0 to 59.4 fps. Agent-tested: medians of 3 fresh loads of a production build in headless Chrome against a seeded Gremlin Server.

  • Tests pin what a badge draws (text, truncation, box, fonts, colors) against the code before this change. They pass unchanged after it.
  • New tests cover culling past each viewport edge, the small-zoom early return, and the cache keys and limit. Each fails when its behavior is broken.

Merge Danger

Door: two-way

Impact: rendering

A badge whose node center sits more than 60 units outside the view is not drawn. Today's badges reach about 45 units from their node's center, so none is cut off at the edge.

Related


🤖 Written by an AI agent on my behalf.

This branch has not been deployed

No deployments
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