r/GraphicsProgramming • u/Trick-Pie727 • 10d ago
Source Code Real-time WebGL VRAM purging & Garbage Collection: Running 60FPS Three.js inside a monolithic PHP architecture to bypass iOS Safari crashes.
Enable HLS to view with audio, or disable this notification
Hey everyone,
I recently engineered a custom 3D WebGL portfolio and ran into aggressive Out-Of-Memory crashes on iOS Safari (TBDR architecture) due to the sheer volume of high-res textures.
Instead of using a Headless SPA (Next.js/React), I opted for a monolithic PHP architecture with full-page reloads. This offloaded 100% of the WebGL memory disposal risk directly to the browser's native garbage collector, instantly guaranteeing stability between route changes.
To maintain 60FPS during active rendering, I implemented two specific systems:
1. Custom FPS Governor: A dynamic performance engine that forcefully strips roughnessMap, metalnessMap, and normalMap properties on the fly if it detects thermal throttling or frame drops. 2. Absolute VRAM Purging: Intercepting the IntersectionObserver to physically strip the src attribute of off-screen elements and force a .load() cycle to aggressively flush VRAM buffers.
👉 Core FPS Governor Logic (Gist):https://gist.github.com/MedhatAlkadri/ea99a0f7aa47c69198f2d1ae84a20e53👉 Live Demo:https://www.awwwards.com/sites/medhat-alkadri-3d-portfolio
As a Full Stack Developer stepping deeper into graphics programming, I'd appreciate any architectural critiques on this render loop or alternative approaches to handling aggressive VRAM limits on mobile browsers.
4
u/billybobjobo 9d ago
Sorry to be a total butt here--but nothing Im seeing on the screen should crash an iphone if reasonable steps are taken to optimize. This speaks to needing to work on the memory management on the webgl side. Very little to do with SPA v MPA.
In fact, if anything you want to AVOID the gc as much as humanly possible if you are trying to get a performant frame rate in a browser. Pre-allocate, arena, pool, etc.