VYPR
researchPublished Oct 9, 2026· 1 source

Cloudflare Introduces On-Demand Profiling for Workers and Durable Objects

Cloudflare now allows developers to generate on-demand CPU and memory profiles for Workers and Durable Objects, visualized as interactive flamegraphs, to pinpoint performance bottlenecks.

Cloudflare has announced a significant enhancement to its developer toolkit with the introduction of on-demand CPU and memory profiling for its Workers and Durable Objects services. This new feature empowers developers to gain deeper insights into the resource consumption of their serverless applications directly within production environments. Previously, understanding performance bottlenecks often relied on logs and aggregate metrics, which could only provide a high-level view. The new profiling capability offers a more granular perspective, enabling the identification of specific functions consuming excessive CPU or allocating large amounts of memory.

The profiling process can be initiated either through the Cloudflare command-line interface (CLI) or the Cloudflare Dashboard. Users can select a specific Worker version and define a duration for the profiling session. It is recommended that the chosen Worker version has sufficient traffic to ensure meaningful data collection. Once initiated, the profiler runs for the specified duration, capturing detailed performance data. The results are then presented as interactive flamegraphs, a visualization technique where each rectangle represents a function call, and its width corresponds to the CPU time or memory allocated. This visual representation allows developers to quickly identify the widest boxes, indicating the most resource-intensive functions.

Developers can interact with the flamegraphs by clicking on functions to focus the view or hovering over them to see detailed information. A table view is also available, offering a quick summary of the most frequently observed functions within the profile. For projects written in TypeScript, enabling source maps is crucial to ensure that the flamegraphs display understandable function names rather than obfuscated code. This feature is designed to be a powerful tool for debugging and optimization, helping developers refine their code for better performance and efficiency.

Cloudflare teams have already leveraged this new profiling capability internally to address various performance issues. One example involved optimizing the Worker that implements the R2 binding. By analyzing a 50-second CPU profile, developers identified a recursive function within genericR2JsonReplacer that was causing redundant processing, making it 2.7 times faster after the fix. Another optimization involved reducing a duplicate call to a metrics function, which alone accounted for 1% of the CPU time in the profile.

Beyond CPU optimizations, the profiling tools have also proven invaluable for diagnosing memory-related problems. In one internal case, a Worker was experiencing frequent evictions due to exceeding its memory limit, resulting in "Exceeded Memory" errors. A heap profile revealed that the Prometheus instrumentation code, which was thought to be disabled, was still consuming a significant portion of the Worker's memory. By identifying and addressing this partially enabled code, the team was able to resolve the memory issues and reduce "Exceeded Memory" errors.

This new on-demand profiling feature represents a significant step forward in Cloudflare's commitment to providing developers with robust tools for building and maintaining high-performance applications on its platform. By offering direct visibility into production resource usage, Cloudflare aims to simplify the complex task of performance tuning and error resolution for its global user base.

Synthesized by Vypr AI