Skip to main content
Performance profiling in Erst helps you identify bottlenecks in smart contract execution by generating interactive flamegraphs that visualize CPU and memory consumption. These flamegraphs show exactly where your contract spends time and resources.

Generating flamegraphs

Enable profiling with the --profile flag:
This generates an interactive HTML file:

Output formats

Choose between HTML and SVG formats:
Generate a standalone interactive HTML file with hover tooltips and zoom:
File: <transaction-hash>.flamegraph.html
HTML is the default format and provides the best user experience. Use SVG only if you need to embed the flamegraph in other tools or documents.

Understanding flamegraphs

Flamegraphs visualize the call stack over time:

Reading the graph

  • X-axis (width): Proportion of time/resources consumed
  • Y-axis (height): Call stack depth (bottom = entry point, top = leaf calls)
  • Colors: Different contract functions and host operations
  • Frame size: Larger frames = more time/resources consumed

Example structure

In this example:
  • transfer consumed 40% of total resources
  • Within transfer, check and update each used 20%
  • mint consumed 30%, all within create_token

Interactive features

Hover tooltips

Hover over any frame to see detailed information:

Click-to-zoom

Click any frame to zoom in and focus on that section:
1

Click a frame

Click on any function in the flamegraph to zoom into that call subtree.
2

Analyze bottleneck

Examine the zoomed view to see all nested calls and their relative costs.
3

Reset zoom

Click the “Reset Zoom” button to return to the full view.
Zooming helps you focus on specific hot paths without visual clutter from other parts of the execution.

Search and highlight

Find specific functions or operations:
1

Open search

Use the search box at the top of the flamegraph.
2

Enter function name

Type the function name, contract ID, or operation you’re looking for.
3

View matches

Matching frames are highlighted in magenta across the entire graph.
4

Clear highlights

Click “Clear” to remove highlights and reset the view.
Search is case-insensitive:

Profiling metrics

CPU consumption

Flamegraphs show CPU instruction counts for each operation:
  • Contract execution: WASM instructions executed
  • Host functions: Built-in Stellar operations
  • Storage operations: Read/write costs
  • Cryptographic operations: Signature verification, hashing

Memory consumption

Memory usage is tracked for:
  • WASM linear memory: Contract heap allocations
  • Host environment: Temporary buffers and state
  • Storage entries: Ledger entry sizes

Analyzing performance issues

Identifying hot paths

Look for the widest frames at each level:
1

Find the widest frame

The widest frame at any level consumes the most resources.
2

Trace upwards

Follow the frame downwards to see what nested calls contribute to the cost.
3

Optimize target

Focus optimization efforts on the leaves of hot paths.

Common performance patterns

Excessive storage reads

Solution: Batch storage reads or cache values.

Deep call stacks

Solution: Flatten call hierarchy or use iterative approaches.

Repeated operations

Solution: Batch operations or use single bulk call.

Profiling workflow

1

Profile the transaction

Generate a flamegraph for your failed or slow transaction:
2

Open in browser

Open the generated HTML file in your browser:
3

Identify bottlenecks

Look for wide frames that consume disproportionate resources.
4

Zoom and search

Use click-to-zoom and search to explore specific hot paths.
5

Correlate with source

Use the file and line information from hover tooltips to locate code.
6

Optimize and re-profile

Make changes to your contract and generate a new flamegraph to verify improvements.

Dark mode support

Flamegraphs automatically adapt to your system theme:
  • White background
  • Dark text
  • Bright colors for frames
Dark mode is detected automatically using CSS media queries. No configuration needed.

Comparing performance

Profile multiple transactions to compare performance:
Open both flamegraphs side by side in your browser to compare:
  • Frame width differences show performance improvements
  • Removed frames indicate eliminated operations
  • New frames show added functionality

Export and sharing

Flamegraphs are standalone files that can be:
  • Shared with team members: Send the HTML file directly
  • Embedded in documentation: Include SVG format in docs
  • Archived for history: Store with transaction data for future reference
  • Opened offline: No external dependencies or network requests

Browser compatibility

Interactive HTML flamegraphs work in all modern browsers:
  • Chrome/Edge 88+
  • Firefox 78+
  • Safari 14+
  • Opera 74+
Very old browsers (IE11, old mobile browsers) may not support all interactive features. Use a modern browser for the best experience.

Tips for profiling

Use profiling early

Profile during development, not just when you have problems:
  • Catch performance issues before deployment
  • Understand baseline costs of operations
  • Compare different implementation approaches

Focus on hot paths

Don’t optimize everything:
  • Target the widest frames (biggest impact)
  • Ignore thin frames (minimal impact)
  • Consider code complexity vs performance gain

Profile realistic transactions

Use representative data:
  • Real-world transaction sizes
  • Typical argument values
  • Expected contract state

Combine with other tools

Use profiling alongside:

Next steps