---
title: "Introducing on-demand CPU and memory profiling with flamegraphs for Workers and Durable Objects"
description: "Cloudflare introduced on-demand CPU and memory profiling for Workers and Durable Objects, accessible via the CLI or the Dashboard’s Observability page. Users can generate interactive flamegraphs and download pprof files, with each rectangle’s width representing CPU time or memory usage over a chosen duration. Profiling the R2 binding Worker revealed that genericR2JsonReplacer, called by JSON.stringify, processed nested values multiple times; fixing it made the function 2.7x faster. A different Worker with P999 memory at 133 MB (above the 128 MB limit) was found to have a partially enabled Prometheus code path accounting for 66.7% of allocations; disabling it reduced P999 memory to 118 MB and eliminated out-of-memory errors. The profiling system locates the correct data center and isolate for the Worker or Durable Object, and continuous profiling is being developed to automatically capture samples without manual initiation."
---

# Introducing on-demand CPU and memory profiling with flamegraphs for Workers and Durable Objects

[Cloudflare](https://yomu.fyi/company/cloudflare) · Dominik Picheta · Oct 9, 2026

**Type:** Announcement

## Summary

Cloudflare introduced on-demand CPU and memory profiling for Workers and Durable Objects, accessible via the CLI or the Dashboard’s Observability page. Users can generate interactive flamegraphs and download pprof files, with each rectangle’s width representing CPU time or memory usage over a chosen duration. Profiling the R2 binding Worker revealed that genericR2JsonReplacer, called by JSON.stringify, processed nested values multiple times; fixing it made the function 2.7x faster. A different Worker with P999 memory at 133 MB (above the 128 MB limit) was found to have a partially enabled Prometheus code path accounting for 66.7% of allocations; disabling it reduced P999 memory to 118 MB and eliminated out-of-memory errors. The profiling system locates the correct data center and isolate for the Worker or Durable Object, and continuous profiling is being developed to automatically capture samples without manual initiation.

## Context

Developers previously lacked the ability to profile Workers and Durable Objects in production, relying on logs and metrics that could not pinpoint specific functions causing high CPU or memory usage.

## Approach / What changed

Cloudflare introduced an on-demand profiler that can be started on a specific Worker version or Durable Object via CLI or Dashboard. The profiler runs for a user-specified duration, captures CPU or heap allocation samples, and renders them as interactive flamegraphs. The infrastructure locates the correct data center and isolate where the Worker or Durable Object is running.

## Takeaways

- The on-demand profiler captures CPU or heap samples of a specific Worker version or Durable Object in production and displays them as interactive flamegraphs.
- Profiling the R2 binding Worker identified that genericR2JsonReplacer processed nested values multiple times; fixing it made the function 2.7x faster.
- A Worker with memory issues had a partially enabled Prometheus code path consuming 66.7% of allocations; removing it reduced P999 memory from 133 MB to 118 MB and eliminated out-of-memory errors.

## FAQ

### How do I start a profiling session for a Worker?

You can start via the CLI using \`cf workers versions profile latest\` with flags for Worker ID, duration, and profile type, or through the Cloudflare Dashboard by navigating to the Worker's Observability tab, selecting 'Flamegraph', and specifying duration and version.

### Can I profile a specific Durable Object?

Yes, when profiling a Durable Object you can choose by name which object to profile. The runtime routes the profiling request to the metal that owns the specific actor and profiles the isolate running that object.

### What are the limitations of on-demand profiling?

You must explicitly start the profiling session, which may cause you to miss misbehavior periods. The memory profiler only shows allocations within the profiling window, so start-up allocations are not captured.

**Tags:** [Observability](https://yomu.fyi/topic/observability), [Performance](https://yomu.fyi/topic/performance), [Serverless](https://yomu.fyi/topic/serverless), [Workers](https://yomu.fyi/topic/workers)

- Source: [Cloudflare](https://blog.cloudflare.com/workers-on-demand-profiling)
- Source URL: https://blog.cloudflare.com/workers-on-demand-profiling
- Ingested by Yomu: 2026-10-09T15:00:13.110Z

[Read original post](https://blog.cloudflare.com/workers-on-demand-profiling)
