Skip to content

Optimize viewer performance for complex toolpaths#5

Merged
bwees merged 4 commits into
prodfrom
claude/optimize-viewer-performance-0C6h2
Apr 7, 2026
Merged

Optimize viewer performance for complex toolpaths#5
bwees merged 4 commits into
prodfrom
claude/optimize-viewer-performance-0C6h2

Conversation

@bwees
Copy link
Copy Markdown
Member

@bwees bwees commented Apr 6, 2026

  • Cache processGCode results to avoid redundant parsing (was called 3-4x for the same G-code: visualizer, outline calc, auto-place, place-model)
  • Fix outline recalculation firing on every machinePosition update - it was re-parsing the entire G-code and computing concave hull on every toolhead move despite machinePosition not being needed for hull calc
  • Make color updates incremental: only paint newly processed lines red instead of resetting ALL vertex colors and repainting from scratch
  • Switch Canvas to frameloop="demand" so the scene only re-renders when something actually changes instead of running at 60fps continuously

https://claude.ai/code/session_01Y2PzWVYwZn4BTd37TWvEVB

- Cache processGCode results to avoid redundant parsing (was called 3-4x
  for the same G-code: visualizer, outline calc, auto-place, place-model)
- Fix outline recalculation firing on every machinePosition update - it
  was re-parsing the entire G-code and computing concave hull on every
  toolhead move despite machinePosition not being needed for hull calc
- Make color updates incremental: only paint newly processed lines red
  instead of resetting ALL vertex colors and repainting from scratch
- Switch Canvas to frameloop="demand" so the scene only re-renders when
  something actually changes instead of running at 60fps continuously

https://claude.ai/code/session_01Y2PzWVYwZn4BTd37TWvEVB
@bwees bwees force-pushed the claude/optimize-viewer-performance-0C6h2 branch from 1d6d7bc to 5c48d05 Compare April 6, 2026 23:50
claude added 3 commits April 6, 2026 23:55
Show a spinner overlay with "Processing toolpath..." when loading complex
G-code files. Moves processGCode from synchronous useMemo to a deferred
useEffect (setTimeout(0)) so React can paint the loading state before
the heavy parsing work blocks the main thread.

https://claude.ai/code/session_01Y2PzWVYwZn4BTd37TWvEVB
The previous approach managed loading state inside the R3F Canvas
reconciler via a callback, but the outer DOM overlay never got a
chance to paint before the heavy work blocked the main thread.

Fix: manage the deferred gcode flow entirely in the outer DOM
component (VisualizerScene). When new gcode arrives:
1. Set isProcessing=true and clear the deferred gcode immediately
2. Wait for double requestAnimationFrame (guarantees browser paint)
3. Only then pass the gcode to GCodeToolpath inside the Canvas

This ensures the spinner overlay is visible before processGCode
blocks the thread. GCodeToolpath reverts to synchronous useMemo
since the deferral now happens at the parent level.

https://claude.ai/code/session_01Y2PzWVYwZn4BTd37TWvEVB
…Panel

The loading indicator was not visible because the heavy work (processGCode
+ concaveman hull calculation) ran synchronously in VisualizerPanel's
event handlers and effects BEFORE VisualizerScene ever received the gcode.

Fixes:
- Remove duplicate calculateOutline calls from the WebSocket handler and
  API restore effect (they were redundant with the loadedGcode effect)
- Defer the outline calculation effect with double requestAnimationFrame
  so the browser can paint the loading overlay before heavy work runs
- Add isProcessingGcode state at VisualizerPanel level and pass it as
  isLoading prop to VisualizerScene
- VisualizerScene shows the spinner when either external isLoading or
  its own internal deferred gcode processing is active

https://claude.ai/code/session_01Y2PzWVYwZn4BTd37TWvEVB
@bwees bwees merged commit de68c2a into prod Apr 7, 2026
8 checks passed
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.

2 participants