Skip to content

perf: eliminate GC pressure in touch/pointer handlers#32

Open
Avatarsia wants to merge 2 commits intoCNCKitchen:mainfrom
Avatarsia:perf/viewer-touch-alloc
Open

perf: eliminate GC pressure in touch/pointer handlers#32
Avatarsia wants to merge 2 commits intoCNCKitchen:mainfrom
Avatarsia:perf/viewer-touch-alloc

Conversation

@Avatarsia
Copy link
Copy Markdown
Contributor

Summary

  • Pre-allocate 7 Three.js temp objects (Plane, Ray x2, Vector3 x2, Vector2 x2) to replace per-event new calls in touch/pointer handlers
  • Mutate _lastPointer and _pinchMid objects instead of creating new { x, y } literals on every event
  • Reuse scene.background.set() instead of new THREE.Color() in theme switching
  • Reuse _tmpSize / _tmpV5 in fitCamera and setProjection

Impact: Eliminates ~360 heap allocations/second during touch drag (pinch-zoom, pan, orbit) on mobile devices. Zero allocations in hot-path event handlers after this change.

Test plan

  • node --check js/viewer.js passes
  • Playwright: app loads without JS errors
  • Playwright: orbit interaction works (pointerdown + pointermove + pointerup)
  • Playwright: theme toggle works without Color errors
  • No console errors across all tests

🤖 Generated with Claude Code

Avatarsia and others added 2 commits April 7, 2026 15:50
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… camera utils

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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