Cloudflare has introduced on-demand CPU and memory profiling for Cloudflare Workers and Durable Objects. According to the announcement, developers can now generate interactive flamegraphs directly in production, making it possible to track down memory leaks and performance bottlenecks without reproducing issues in staging. This brings a capability common in long-running server environments into Cloudflare's serverless edge runtime.
The concrete changes include:
- On-demand profiling for both Workers and Durable Objects, initiated when a problem is suspected rather than running continuously.
- CPU profiles that identify hot code paths consuming execution time.
- Memory profiles aimed at exposing leaks and excessive allocations.
- Interactive flamegraphs generated directly from production traffic, so developers can inspect call stacks visually.
- Availability without requiring local reproduction, targeting issues that only surface under real load.
For developers, this matters because Workers and Durable Objects run in a managed, distributed environment where traditional host-level profiling tools are unavailable. When a Worker exhibits latency spikes or a Durable Object slowly grows in memory, diagnosing the cause previously required guesswork, logging, or reproducing the workload elsewhere. Flamegraphs generated in production shorten that feedback loop: instead of inferring the bottleneck from logs, developers can see which functions dominate CPU time or where allocations accumulate.
Memory leaks are particularly relevant for Durable Objects, which are stateful and long-lived. A slow leak can degrade a single object over time, and on-demand memory profiling gives a direct view into that growth. For stateless Workers, CPU profiling helps identify inefficient serialization, excessive object creation, or unexpected blocking work along the request path.
The feature reinforces a broader trend of bringing production observability to serverless platforms. Developers can now profile the exact code running under real traffic conditions, closing the gap between local testing and edge execution. Teams adopting Workers for latency-sensitive or stateful workloads should evaluate profiling as part of their debugging toolkit.
Source: https://blog.cloudflare.com/workers-on-demand-profiling/