Profiling Your Application
Debug Metrics (F12)
Iced includes built-in performance metrics accessible by pressing F12 during development: Enable debug features:- Frame time - Time to render each frame
- Update time - Time spent in your update logic
- View time - Time to build the widget tree
- Layout time - Time to compute layouts
- Draw time - Time to generate rendering primitives
- Layers rendered - Number of rendering layers
- Messages logged - Recent update messages
Time-Travel Debugging
For message flow analysis:- Message history tracking
- State rewind/replay
- Performance analysis per message
External Profilers
For deeper analysis, use: Tracy profiler integration:Widget Tree Optimization
Avoid Rebuilding Views
Only rebuild views when state changes:Use Efficient Containers
Lists and scrollables:Cache Expensive Computations
Rendering Optimization
Choose the Right Renderer
wgpu (GPU):- Best for complex animations
- Hardware-accelerated
- Better for large windows
- Higher memory usage
- Better for simple interfaces
- Lower memory footprint
- More predictable performance
- No GPU driver issues
Configure Present Mode
Control frame rate with present modes:Antialiasing Trade-offs
Minimize Layer Count
Layers add overhead:Batch Drawing Operations
The renderer automatically batches similar operations, but you can help:Memory Optimization
Image Caching
Images are automatically cached, but you can control it:Font Loading
Load fonts once at startup:Avoid Large Widget Trees
Message Handling
Batch Updates
Debounce Expensive Operations
Async Operations
Use Efficient Executors
Avoid Blocking the UI
Canvas Optimization
For the Canvas widget:Build Optimization
Release Profile
Feature Flags
Only enable what you need:Platform-Specific Optimization
Linux
Windows
macOS
Monitoring Performance
Add Custom Metrics
System Information
Monitor resource usage:Common Performance Pitfalls
-
Rebuilding the entire widget tree on every update
- Use
lazywidgets - Split state to minimize redraws
- Use
-
Excessive cloning in view functions
- Pass references when possible
- Use
Arcfor shared data
-
Not caching expensive computations
- Memoize results
- Use
lazy_staticorOnceCell
-
Too many subscriptions
- Combine related subscriptions
- Unsubscribe when not needed
-
Large images without optimization
- Resize images to display size
- Use appropriate formats (WebP, etc.)
-
Synchronous file I/O
- Always use async for file operations
- Show loading states
Next Steps
- Use Debugging tools to identify bottlenecks
- Review Renderer Architecture for backend choices
- Learn about Custom Renderers for specialized needs
