Overview
Hoot includes optional profiling support using the puffin profiler. When enabled, this feature allows you to analyze application performance, identify bottlenecks, and optimize rendering and event processing.Building with profiling enabled
The profiling feature is controlled by a Cargo feature flag. To build Hoot with profiling support:RUST_BACKTRACE=1 cargo run --features profiling for development with full backtraces and profiling enabled.
How profiling works
When theprofiling feature is enabled, Hoot automatically:
- Starts a puffin HTTP server on
127.0.0.1:8585 - Attempts to launch puffin_viewer to visualize the profiling data
- Collects performance data throughout the application lifecycle
Architecture details
The profiling system is configured insrc/main.rs:
Setting up the puffin viewer
Run Hoot with profiling
Start Hoot with the profiling feature enabled:Hoot will automatically attempt to launch the puffin viewer.
Using the profiler
Viewing performance data
Once connected, the puffin viewer displays:- Frame timings - Time spent rendering each frame
- Scope hierarchies - Nested performance scopes showing where time is spent
- Flame graphs - Visual representation of execution time
- Statistics - Min, max, and average times for profiled operations
Key areas to profile
In Hoot, pay attention to:- UI rendering (
render_app()and component render functions) - Event processing (
update_app()and relay message handling) - Database operations (event storage and queries)
- Gift wrap encryption/decryption (message privacy operations)
- WebSocket communication (relay connection handling)
Performance optimization tips
Immediate mode UI considerations
Hoot uses egui, an immediate-mode GUI framework. Common optimization strategies:- Avoid expensive operations in render functions
- Cache computed data when possible
- Use
ui.ctx().request_repaint()sparingly - Profile with realistic data sets (many messages, contacts, etc.)
Database optimization
The SQLite database uses generated virtual columns for efficient querying:- Profile queries with realistic event counts
- Check if indexes are being used effectively
- Monitor transaction patterns
Network and async operations
While relay operations useewebsock with callbacks:
- Profile the wake-up callback frequency
- Monitor message processing backlog
- Check gift wrap decryption performance
Profiling in CI/CD
The profiling feature adds dependencies (
puffin and puffin_http) that are only needed during development. It should not be enabled in release builds or CI/CD pipelines.Dependencies
The profiling feature adds the following optional dependencies inCargo.toml:
Troubleshooting
Server fails to start
If the puffin server fails to start:- Check if port 8585 is already in use
- Verify firewall settings allow localhost connections
- Check application logs for error messages
Viewer can’t connect
If the viewer can’t connect to the server:- Ensure Hoot is running with
--features profiling - Verify the viewer is connecting to
127.0.0.1:8585 - Check that the puffin server started successfully (check logs)
No profiling data visible
If the viewer connects but shows no data:- Verify
puffin::set_scopes_on(true)is being called - Check that profiling scopes are added to the code you’re measuring
- Ensure the application is actively running and processing events