
Project Types:#Side Project#Web
Tech Stacks:#TypeScript#React#React Three Fiber#Three.js#Zustand#Sanity.io#TailwindCSS
Optimizing WebGL Render Loops for Sub-16ms Frame Times
🎯The Challenge
The objective was to engineer a high-fidelity 3D gallery capable of rendering real-time reflections and complex geometry across devices. The core technical constraint was performance: initially, relying on standard DOM manipulation or React state for 3D camera movements caused significant main-thread blocking and frame drops (sub-30FPS) on mobile hardware due to excessive garbage collection and re-rendering.

🛠️The Engineering
To solve the latency issues, I architected a hybrid render system that decouples the animation loop from the React reconciliation process and leverages linear algebra for responsive layout.
- Render Loop Optimization: I bypassed React's Virtual DOM for the animation critical path. Instead of triggering re-renders for camera movements, I implemented transient state updates using the
useFramehook to mutate the WebGL scene graph directly. This enabled smooth interpolation ofVector3andQuaternionstructures while keeping the frame budget under 16ms. - Vector-Based Camera Automation: I replaced hardcoded camera transitions with dynamic Matrix Transformations. By calculating
localToWorldcoordinates and utilizing Quaternion interpolation for rotations, I eliminated Gimbal Lock issues and ensured precise camera tracking regardless of the object's nesting depth in the scene graph. - Geometric Responsive Design: To handle the constrained Field of View (FOV) on mobile devices, I implemented an adaptive Z-axis offset algorithm. The system detects viewport aspect ratio in real-time and dynamically recalculates the camera's render distance, ensuring 3D assets remain perfectly framed without cropping—distinguishing this from standard 2D CSS media queries.
- Math-Driven Visibility Culling: I engineered a proximity-based opacity system within the render loop. By calculating the Euclidean distance between the camera and objects on every frame, the application automatically culls (fades out) irrelevant assets. This mimics a depth-of-field effect using performant CPU logic rather than computationally expensive GPU post-processing shaders.
- Deterministic Asset Indexing: To handle scene navigation efficiently, I implemented a hashing strategy using
uuid-by-string. This created deterministic, unique identifiers for dynamic assets, enabling O(1) lookups for active frames.

🚀The Impact
- Performance: Achieved a consistent 60 FPS on desktop and stable 30+ FPS on mid-tier mobile devices by offloading visual effects to math-based logic and restricting React re-renders to state changes only.
- Latency: Reduced perceived latency to near-zero for camera interactions by handling physics interpolation on the frame loop rather than the event loop.
- Scalability: The deterministic UUID architecture allows the gallery to scale from 5 to 500+ assets without refactoring the navigation logic or degrading lookup performance.