> ## Documentation Index
> Fetch the complete documentation index at: https://glassen.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Measure and tune glass performance

> Measure frame pacing and memory use, and reduce the work each lens adds.

Glassen shares a clock, sources and GPU resources within a surface. Performance depends on the pixel area covered, source work and overlap, as well as the number of lenses.

Use one shared surface for collections. Reuse source and shape objects. Keep static source versions stable, and use GPU sources for continuously changing content. DOM snapshots are suitable for text and occasional updates, but repeated captures add CPU work and uploads.

## Read the counters

| `surface.stats` field | Meaning |
| - | - |
| `instances`, `visible` | Mounted lenses and those painted this frame |
| `drawCalls` | Glass draws this frame |
| `sceneDrawCalls` | Scene content work this frame |
| `backdropCopies` | GPU snapshots required by overlapping paint bounds |
| `uploads` | Sampled image/canvas uploads this frame; GPU producers may do their own work |
| `textureBytes` | Estimated owned texture storage |
| `cpuMs` | JavaScript submission time for the frame |
| `intervalMs` | Interval between rendered animation callbacks |
| `frames` | Completed render callbacks |

These counters do not measure GPU completion or displayed frames. Browser/GPU caches and driver allocations are outside `textureBytes`.

## Frame pacing

Surfaces stop issuing draws when their canvas leaves the viewport, including inside an embedded preview, and resume when it returns. Source activity follows the same visibility boundary.

The renderer follows `requestAnimationFrame` and device pixel ratio, without adaptive resolution. A 120 Hz display gives about 8.3 ms per frame; 60 Hz gives about 16.7 ms. Large lenses, overlapping layers and expensive source rendering can exceed those budgets. No device-independent FPS or instance-count guarantee is made.

Measure in a visible browser on the target device. Chrome's frame-rendering stats and Performance trace distinguish presentation stalls, CPU work and GPU pressure. Test dragging, resize, multiple instances, background/resume and removal. A deterministic 4K60 recording proves the captured frame sequence; it does not prove real-time playback at 4K60.

## Lifetime checks

Repeatedly mount and unmount the same scene. Owned textures and subscriptions should be released after consumers are removed; the WASM allocator may keep its grown memory for reuse. A memory plateau is different from growth on every cycle. Close GPU consumers before destroying their source or shape.

Hidden/offscreen rendering pauses. A source can stop background work through `setActive`; it must account for every owner when shared. Avoid adding independent timers or render loops inside source adapters.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.