bonjour ~ $ 

High-Performance WebGL Simulation Dashboard

Re-architecting a physics-driven Three.js dashboard of ~7,000 simulated entities so it loads without stalling, renders correctly from the first frame, and holds 60 FPS on desktop and mobile.

View the live dashboard (it takes around 10 seconds to load the full simulation)

Client
Private client (Upwork)
Year
2026
Role
Frontend / WebGL engineer
Stack
Next.js 15, React 19, Three.js, Matter.js, Web Workers
Simulation dashboard on a dark grid: purple cell-like entities, some loose and some packed into large clusters, under a green HUD with zoom controls and a stats panel.
The live dashboard: loose entities and bonded clusters, with the HUD in the client's custom typeface.
entities simulated and rendered
~7,000
stable on desktop and mobile
60 FPS
per-message serialization removed
~100 ms
client rating
5.0 / 5

The problem

The client's dashboard, built with Next.js 15, React 19 and vanilla Three.js, already reached up to ~180 FPS on desktop once it had loaded. Getting there was the issue: a slow, janky start, incorrect first frames and a mobile experience that was largely broken. An audit traced it to four root causes.

  • Physics rebuilt from scratch

    The Matter.js engine was created, run for 15 steps and destroyed on every calculation. With ~7,000 bodies that meant 1–2 s of work per run and heavy garbage-collection churn.

  • Costly worker transport

    Physics already ran in a Web Worker, but every message serialized Map → Array → Map, adding about 100 ms of overhead, and a long calculation could not be cancelled when new data arrived.

  • Wrong first frame

    The UI could render before the full data set arrived, so the first frames showed collisions, missing connections, ordering errors and cells jumping into place.

  • Broken on mobile

    Frustum culling was disabled on the instanced meshes, so the GPU processed off-screen geometry; entities did not render properly on phones and touch gestures and scrolling misbehaved.

How I worked

  1. Step 1

    Performance audit

  2. Step 2

    Proof-of-concept sprint

  3. Step 3

    Engine refactor

  4. Step 4

    Mobile & Web3 polish

Rather than patching symptoms in the UI, I started with a scoped performance sprint to prove that a zero-copy transport and a stateful worker would remove the start-up lag, before committing to the full refactor. Race conditions and rendering traps were documented in short Loom videos, so the client could see why the main thread was rendering too early. When mobile wallet connections failed, I traced the conflict to the security headers and set out a fix before building it.

Key technical decisions

  • A persistent physics engine instead of a rebuild per run

    What: the Matter.js engine now lives for the whole session inside the worker and is updated incrementally, with a spatial hash grid for collision checks instead of O(N²) comparisons.

    Why: no more creating and clearing 7,000 bodies on every calculation, so the 1–2 s initialisation lag and the garbage-collection spikes are gone.

  • Zero-copy transport with SharedArrayBuffer

    What: the worker writes entity positions straight into shared memory that the render loop reads, replacing the Map → Array → Map serialization on every message.

    Trade-off: SharedArrayBuffer requires the page to be cross-origin isolated (COOP/COEP headers), which later clashed with Web3 wallet pop-ups.

  • Write-locks and a promise bridge between threads

    What: an atomic write-lock on the shared buffer plus a promise-based handshake, so the UI only renders once the full 7,000-entity frame has arrived.

    Why: this removed the race conditions behind black grids, missing connections and cells jumping on load, and keeps the visual state in step with the physics state.

  • Organic layout from Gaussian repulsion

    What: the rigid, grid-like starting positions were replaced by Gaussian-random repulsion with feathered boundaries.

    Why: a natural "petri dish" look the client wanted, while keeping coordinates deterministic enough for the physics and bond rendering.

  • A non-isolated wallet bridge for Web3

    What: a separate /wallet-bridge route runs without cross-origin isolation, completes the handshake with wallets such as Phantom and Brave, stores the session in a domain-wide cookie and sends the user back to the isolated 3D canvas.

    Why: the high-performance canvas keeps its SharedArrayBuffer, and wallet connections persist across subdomains, with loading states covering the canvas remount.

Architecture

Simulation engine architectureThe backend data stream feeds a persistent Matter.js engine in a Web Worker, which uses a spatial hash grid for collisions. The worker writes positions into a SharedArrayBuffer. On the main thread, the Three.js render loop reads that buffer into instanced meshes once a full frame of data is ready. The canvas runs cross-origin isolated; a separate, non-isolated wallet bridge route handles Web3 wallet connections and hands the session back through a cookie.Backend data stream~7,000 entities, 15 ms updatesWeb WorkerPersistent Matter.js engine + spatial hash gridSharedArrayBufferZero-copy positions, write-lockedMain thread (cross-origin isolated)Three.js loopRenders when frame is completeInstancedMeshCulling on, one draw call/wallet-bridgeNon-isolated routeWalletPhantom, Brave

The outcome

  • A stable 60 FPS on mobile and desktop for ~7,000 active entities, running against a 15 ms backend data stream.
  • Correct first frames: no collisions, missing connections or jumping cells on load.
  • Mobile fixed: frustum culling restored, scaling issues resolved, and touch gestures and scrolling working.
  • Bond rendering corrected so signals travel to the midpoint of a connection instead of passing through it, and the client's custom typography applied.
  • Wallet connections that survive the cross-origin isolation the engine depends on.

Screenshots

Zoomed-in view of one cluster: hundreds of glowing purple entities packed together, with fine bond lines between neighbours.
Zoomed in on a cluster: entities held together by bonds, rendered from one instanced mesh.
The same dashboard on a phone-sized screen, showing entities and clusters with a compact header and menu.
Mobile: the full simulation renders with a compact, touch-friendly layout.

Walkthrough

Video walkthrough coming soon
Short walkthrough of the dashboard running at full entity count.

Client feedback

“Outstanding experience! Highly recommended!”
Client review on Upwork, 5.0 / 5. Endorsed as Committed to Quality, Solution Oriented and Clear Communicator. The client went on to ask me to build the platform's main landing page.
Get in touch

© 2023 Aindrajaya. All rights reserved