Cache Complex PixiJS Graphics with RenderTexture: Draw Calls vs GPU Memory
PixiJS Graphics rebuilds its command list every frame. RenderTexture can bake complex vector art into one texture, cutting draw calls but requiring manual invalidation and GPU memory budgeting.
05 Dec 2025, 17:58 UTC

The Problem: Graphics Command Lists Rebuild Every Frame
PixiJS Graphics objects store drawing commands—lines, arcs, fills, and styles—and the renderer replays that list every frame. A map background or UI frame with hundreds of commands can consume CPU time building commands and GPU time issuing draw calls. On mobile, that overhead can drop frames before any game logic runs.
What RenderTexture Caching Actually Does
RenderTexture renders a Container or Graphics once into an offscreen texture. You then display that texture as a Sprite. The renderer draws a single textured quad instead of walking the original command list. PixiJS can also batch multiple Sprites that share the same RenderTexture, reducing texture bindings.
The cache is not live. If you modify the source Graphics, the Sprite keeps showing the old texture until you explicitly render the source into the RenderTexture again.
Worked Example: Cache a Detailed Map Background
Suppose mapGraphics draws a tiled map with hundreds of line and fill commands. You want to cache it at its displayed size, for example 1920×1080, then show it as a Sprite.
// 1. Create the RenderTexture at display size
const renderTexture = RenderTexture.create({
width: 1920,
height: 1080,
scaleMode: SCALE_MODES.LINEAR,
resolution: renderer.resolution
});
// 2. Render the Graphics into the texture once
renderer.render(mapGraphics, { renderTexture });
// 3. Show the cached texture as a Sprite
const mapSprite = new Sprite(renderTexture);
mapSprite.position.set(0, 0);
stage.addChild(mapSprite);
// 4. Remove the original Graphics from the render tree
mapGraphics.parent?.removeChild(mapGraphics);
// 5. Re-render when the map changes
function updateMap() {
mapGraphics.clear();
// rebuild mapGraphics commands here
renderer.render(mapGraphics, { renderTexture });
}
Where to run: In your PixiJS application code after the renderer and stage exist. No special permissions beyond a valid WebGL context.
Meaningful placeholders: 1920 and 1080 should match the actual on-screen dimensions of the cached artwork. renderer.resolution keeps the texture crisp on high-DPI displays.
Expected checks: Open browser DevTools, record a frame, and compare renderer.stats.drawCalls before and after caching. The cached Sprite should contribute roughly one draw call for that asset.
Risks: If the texture exceeds the device maximum size (commonly 4096×4096 on mobile), creation can fail. Large textures also consume GPU memory proportional to width × height × 4 bytes.
Trade-offs and Limitations
| Benefit | Cost / Limitation |
|---|---|
| Reduces draw calls from dozens or hundreds to one | GPU memory grows with texture dimensions; a 1920×1080 cache is roughly 8 MB |
| Multiple Sprites can batch on the same cached texture | No automatic invalidation; source changes are invisible until you re-render |
| Removes per-frame command-list traversal | Texture upload on each update can spike frame time if done frequently |
| Simplifies the scene graph for static art | Lost on WebGL context loss; rebuild after context restore |
Memory pressure is the most common pitfall. On low-end mobile devices, several large caches can trigger texture eviction or out-of-memory crashes. Keep dimensions close to the displayed size and destroy caches you no longer need.
Verification Steps
- Draw-call comparison: Render the complex Graphics directly, note
renderer.stats.drawCalls. Cache it, render the Sprite, and confirm the count drops for that asset. - Staleness check: Change a color or shape in the source Graphics after caching. The Sprite must remain unchanged until you call
renderer.render(source, renderTexture)again. - GPU memory inspection: Use browser DevTools to inspect GPU memory before and after adding the cache. Expect growth near width × height × 4 bytes.
- Low-end device test: Test on a device with limited GPU memory. Confirm frame time improves and no texture-size warnings appear in the console.
Closing: Profile Before You Cache
RenderTexture caching is a targeted optimization, not a default. Profile first: if your frame budget is lost to Graphics command traversal, cache the heaviest static asset. Measure draw calls and GPU memory on real hardware, rebuild caches after context loss, and destroy them when they are no longer needed.