Skip to content

perf: optimize hover handling to prevent unnecessary re-renders#677

Open
agent-steven wants to merge 1 commit intotscircuit:mainfrom
agent-steven:fix/hover-performance
Open

perf: optimize hover handling to prevent unnecessary re-renders#677
agent-steven wants to merge 1 commit intotscircuit:mainfrom
agent-steven:fix/hover-performance

Conversation

@agent-steven
Copy link

/claim #94

Summary

Fixes the major slowdown when hovering over components in the 3D viewer.

Problem

As noted by @DrSensor, the hover system was triggering excessive re-renders because:

  1. onHover was called on every mouse move event
  2. Even when hovering the same object, position updates triggered state changes
  3. No throttling on mousemove events

Solution

Optimized HoverContext.tsx with:

  1. Throttling: Limited mousemove processing to ~60fps (16ms intervals)
  2. Position-based filtering: Only trigger onHover when:
    • Hovering a different object, OR
    • Position changed by more than 0.1 units (threshold)
  3. Proper cleanup: Reset position tracking on unhover

Changes

  • src/react-three/HoverContext.tsx: Added throttling and position-based filtering

Testing

The fix reduces unnecessary onHover calls from hundreds per second to only when meaningful changes occur, significantly improving frame rate and reducing CPU usage.

Add throttling and position-based filtering to hover events:

1. Throttle mousemove events to ~60fps (16ms)
2. Skip onHover calls when hovering same object if position
   hasn't changed beyond threshold (0.1 units)
3. Clean up position tracking on unhover

This reduces CPU usage and prevents re-render storms when
moving mouse over 3D components.

Fixes tscircuit#94
@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment Feb 5, 2026 0:28am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants