Debug Overlay (F12)
The most immediate debugging tool is the built-in debug overlay.Enabling Debug Features
Using the Debug Overlay
- Run your application in debug mode
- Press F12 to toggle the debug overlay
- View real-time performance metrics
- Frame time - Total time per frame (aim for < 16.67ms for 60 FPS)
- Update - Time in your
update()function - View - Time building the widget tree
- Layout - Time computing widget positions and sizes
- Draw - Time generating rendering primitives
- Prepare - Time preparing GPU/CPU resources
- Render - Time submitting draw calls
- Present - Time presenting to screen
- Layers - Number of rendering layers (fewer is better)
- Messages - Recent messages processed
Interpreting Metrics
High Update time:- Your business logic is too expensive
- Consider async processing
- Check for expensive cloning or allocations
- Widget tree is too large
- Use
lazywidgets to reduce rebuilds - Profile view function with external tools
- Too many complex layouts
- Simplify container nesting
- Avoid dynamic sizing when possible
- Too many primitives being generated
- Check for widget duplication
- Reduce number of draw calls
- Reduce nested scrollables
- Limit clipping operations
- Each layer has overhead
Time-Travel Debugging
Time-travel debugging lets you rewind and replay your application state.Enabling Time Travel
Using Time Travel
- Run your app with time-travel enabled
- Press F12 to open the debug overlay
- The Comet debugger will launch (auto-installed on first use)
- See message history and rewind to any point
- View all messages in chronological order
- Click any message to rewind to that state
- See message payloads and timing
- Replay message sequences
Requirements
YourMessage type must implement Debug and optionally Clone:
State must be deterministic (no randomness or timestamps in update).
Comet Debugger
Comet is Iced’s official companion debugger tool.Features
- Performance metrics - Real-time charts and graphs
- Message timeline - Visual message flow
- State inspection - View application state
- Theme preview - See current theme palette
- Command tracking - Monitor async tasks
- Subscription monitoring - See active subscriptions
Installation
Comet is automatically installed when you first press F12 with debug features enabled. Manual installation:Connecting to Comet
Comet connects to your app via a local socket. Press F12 in your running application to establish the connection.Hot Reloading
Hot reloading allows you to see code changes without restarting your app.Enabling Hot Reloading
Using Hot Reloading
Wrap hot-reloadable code withdebug::hot:
debug::hot will be applied without restart.
Limitations:
- Only works with code inside
debug::hotblocks - Cannot change function signatures
- Cannot add/remove fields from structs
- State is not preserved across hot patches
Detecting Stale Code
Check if types have changed:On Hotpatch Callbacks
Run code when a hotpatch occurs:Custom Debug Spans
Instrument your code with custom timing spans:Logging
Use Rust’s standard logging infrastructure:Testing
Iced provides a testing framework for automated tests.Enabling the Tester
Recording Tests
- Press F12 in your running app
- Perform actions you want to test
- Test interactions are recorded
- Export as test code
Running Tests
Headless Testing
Test rendering without a display:Environment Variables
Debug Control
Renderer Debugging
Platform-Specific
Performance Profiling
Tracy Integration
For advanced profiling:Flamegraphs
System Monitoring
Common Issues
Application Freezes
Symptoms: UI becomes unresponsive Debug steps:- Check F12 overlay for long Update times
- Look for blocking I/O in update function
- Search for infinite loops or recursion
- Profile with external tools
Slow Rendering
Symptoms: Low FPS, stuttering Debug steps:- Check Draw/Render times in F12
- Count layers (high = problem)
- Profile View function
- Check for massive widget trees
Memory Leaks
Symptoms: Memory usage grows over time Debug steps:- Use memory profilers (heaptrack, valgrind)
- Check for growing caches
- Look for unreleased resources
- Verify Task completion
Graphics Issues
Symptoms: Visual glitches, crashes Debug steps:- Try different backends:
WGPU_BACKEND=vulkan - Update graphics drivers
- Check for GPU errors:
RUST_LOG=wgpu=debug - Test with tiny-skia renderer
Debug Assertions
Enable strict assertions during development:Conditional Rendering
Add debug-only widgets:Tips
- Always use the F12 overlay first - It shows 90% of issues
- Enable debug features only in dev - They add overhead
- Use time-travel for message flow issues - Invaluable for complex flows
- Profile with external tools for deep issues - flamegraph, perf, Tracy
- Test with both renderers - Helps isolate GPU vs logic issues
- Use logging liberally - Easy to add, easy to filter
- Write tests early - Catch regressions fast
Next Steps
- Review Performance optimization techniques
- Understand the Renderer Architecture
- Create Custom Renderers with debug support
