Documentation Index
Fetch the complete documentation index at: https://mintlify.com/risc0/risc0/llms.txt
Use this file to discover all available pages before exploring further.
Profiling Guest Programs
Profiling is one of the most important tools for understanding and optimizing zkVM guest code. This guide shows you how to generate cycle-count profiles and visualize them using flamegraphs.Background
Profiling tools like pprof and perf allow collecting performance information over the entire execution of your program. RISC Zero has experimental support for generating pprof files for cycle counts.How Profiling Works
Sampling CPU profilers record the current call stack at regular intervals to show where your program spends its time. RISC Zero’s profiler captures the call stack at every cycle of program execution.The zkVM profiler captures the call stack at every cycle, not at sampling intervals. This is practical because zkVM executions are short and synchronous, with no measurement overhead.
Prerequisites
Follow the installation guide if you haven’t already.
The pprof tool is bundled with Go. Install Go for your platform.
Generating Profiles
Basic Usage
Set theRISC0_PPROF_OUT environment variable to specify where to write profiling data:
Example: Profiling ECDSA Verification
Environment Variables
| Variable | Purpose | Example |
|---|---|---|
RISC0_PPROF_OUT | Output file path for profiling data | ./profile.pb |
RISC0_DEV_MODE | Enable dev mode (skip proving) | 1 |
RISC0_INFO | Show execution statistics | 1 |
RISC0_PPROF_ENABLE_INLINE_FUNCTIONS | Track inlined functions (slower) | yes |
Visualizing Profiles
Starting the pprof Web Interface
After generating a profile, visualize it with:Flamegraph View
The flamegraph is one of the most useful visualizations. Access it at:In a flamegraph:
- The x-axis represents the proportion of total cycles
- The y-axis represents the call stack depth
- Wider sections indicate more cycles spent
- Click on sections to zoom in
Example Flamegraph
When viewing a flamegraph from ECDSA signature verification, you’ll typically see that thelincomb (linear combination) operation accounts for over 95% of the total cycle count in ECDSA verification.
Profiling Example: Fibonacci
The profiling example compares three Fibonacci implementations:Implementation 1: Basic Iterative
Implementation 2: Loop Unrolling
Implementation 3: Matrix Exponentiation
Running the Example
Advanced Features
Tracking Inline Functions
Compilers often inline functions, which can make profiles less detailed. If you’ve compiled with debug symbols, enable inline function tracking:Other pprof Views
The pprof web interface provides several visualization options:- Top: List of functions by cycle count
- Graph: Call graph with cycle counts
- Peek: Examine specific functions
- Source: View source code with cycle annotations (requires debug symbols)
- Disassemble: View assembly with cycle counts
Profiling Best Practices
Interpreting Results
Understanding Cycle Counts
Remember that cycle counts are directly proportional to proving time. A function that takes 1 million cycles will require roughly twice as long to prove as a function that takes 500,000 cycles.Page-In/Page-Out Detection
If you see functions with names likepage_in or page_out consuming significant cycles, consider:
- Reducing memory usage
- Improving memory locality
- Using more compact data structures
Cryptographic Operations
If cryptographic operations dominate your profile, check if you’re using precompiled implementations. Precompiles can reduce cycle counts by 10-100x for supported operations.Next Steps
- Apply insights from profiling using the Optimization Guide
- Explore Precompiles for cryptographic acceleration
- Learn about GPU Acceleration for faster proving