Performance Optimization
This guide covers performance optimization techniques for Filament applications, from engine configuration to rendering best practices.Engine Configuration
Memory Configuration
Filament’s memory footprint is configurable viaEngine::Config:
JobSystem Configuration
jobSystemThreadCount can help in CPU-constrained environments where too many threads cause contention.
Rendering Optimizations
Frame Pacing
Configure display information for proper frame pacing:Dynamic Resolution Scaling
Use dynamic resolution to maintain target frame rates:Automatic Instancing
Enable automatic instancing for identical primitives:Material Optimization
Material Variants
Filament generates shader variants based on:- Directional lighting
- Dynamic lighting
- Shadow receivers
- Skinning
- Fog
- Disabling unused features in materials
- Using static variants when possible
- Sharing material instances across renderables
Material Batching
The engine batches material instances using a shared uniform buffer:Geometry Optimization
Vertex Buffers
Use appropriate vertex formats:| Type | Size | Use Case |
|---|---|---|
| HALF2 | 4 bytes | UVs, compressed normals |
| HALF4 | 8 bytes | Positions (small range) |
| FLOAT2 | 8 bytes | UVs (high precision) |
| FLOAT3 | 12 bytes | Positions, normals |
| FLOAT4 | 16 bytes | Full precision |
Index Buffers
Use 16-bit indices when possible:Culling
Provide accurate bounding boxes for frustum culling:Texture Optimization
Texture Formats
Use compressed formats:Mipmaps
Always generate mipmaps for textures:mipgen tool to generate mipmaps offline:
Texture Streaming
For large textures, use asynchronous uploads:Scene Optimization
Reduce Draw Calls
- Batch static geometry into fewer renderables
- Use instancing for repeated objects
- Minimize material switches by sorting renderables
- Use texture arrays instead of texture atlases
Light Count
Limit visible lights:Shadow Maps
Optimize shadow map configuration:Backend-Specific Optimizations
Vulkan
Metal
OpenGL
Profiling and Debugging
Frame Timing
Get frame timing information:GPU Queries
Frame info includes:Resource Tracking
Monitor resource counts:Best Practices
Do’s
✓ Batch static geometry to reduce draw calls✓ Use instancing for repeated objects
✓ Provide tight bounding boxes for culling
✓ Use compressed textures with mipmaps
✓ Enable automatic instancing when appropriate
✓ Configure memory based on your scene complexity
✓ Profile regularly using frame timing
Don’ts
✗ Don’t create/destroy resources every frame✗ Don’t use full precision when half precision suffices
✗ Don’t skip mipmaps for textures
✗ Don’t use too many material variants
✗ Don’t ignore frame pacing warnings
✗ Don’t exceed command buffer size
Measuring Performance
See Also
- Custom Backends - Backend selection
- Threading Model - JobSystem usage
- Debugging Tools - matdbg and profiling