THE CRUNCH
Cloudflare has launched on-demand CPU and memory profiling for Workers and Durable Objects, its serverless compute platform. From the Workers Observability page, developers can request a profile of an active Worker, view the results as an interactive flamegraph, and download the profile file for deeper analysis. Profiles can be captured through the Cloudflare dashboard or the CLI.
A flamegraph is a chart of function calls where each rectangle represents a function, and its width shows how much CPU time or memory that function consumed. Cloudflare argues that profiling in production beats logs and aggregate metrics, because it points to the exact function where resources are being spent. Developers can choose the profiling duration, select which version of a Worker to profile, and should pick a version with plenty of traffic for the capture to succeed.
The company says its own teams have already used the feature to good effect. A CPU profile of the Worker behind the R2 storage binding revealed a JSON replacer that was walking the same data tree twice, once via JSON.stringify and once on its own; fixing the duplicated work made that function 2.7x faster. In another case, a heap profile showed that Prometheus instrumentation code, believed to have been disabled, was only partially switched off and was still consuming enough memory to push a Worker past its 128 MB limit and trigger frequent evictions.
Two practical caveats apply. TypeScript projects need source maps enabled, otherwise profiles show obfuscated function names. And Cloudflare suggests capturing a few profiles and looking for the widest functions, or using the table view, to spot the heaviest resource consumers.


