Live
K2 Stream Observability: New Dashboard Metrics and GraphQL API AccessGitHub Issue Statuses and Repository Boards Enter Public Preview – What Engineers Need to KnowAgentic SOC in Google Cloud SIEM: Practical Implications for EngineersSlack webhook secret scanning tightened to cut false positivesClaude Ship PR automation: AI agents now review and approve pull requestsProfiling Worker Previews: On‑Demand CPU and Heap Insights for Faster IterationPredictable costs with the new AWS WAF pricing modelProtecting AI‑augmented APIs on AWS with API Portal and WAF rule groupsK2 Stream Observability: New Dashboard Metrics and GraphQL API AccessGitHub Issue Statuses and Repository Boards Enter Public Preview – What Engineers Need to KnowAgentic SOC in Google Cloud SIEM: Practical Implications for EngineersSlack webhook secret scanning tightened to cut false positivesClaude Ship PR automation: AI agents now review and approve pull requestsProfiling Worker Previews: On‑Demand CPU and Heap Insights for Faster IterationPredictable costs with the new AWS WAF pricing modelProtecting AI‑augmented APIs on AWS with API Portal and WAF rule groups
Cloudflare

Profiling Worker Previews: On‑Demand CPU and Heap Insights for Faster Iteration

AI SummaryPowered by AI

Cloudflare now lets you capture on‑demand CPU and memory profiles from Worker Preview deployments. This gives engineers a safe way to measure and optimise code before it reaches production.

Cloudflare has added the ability to run on‑demand CPU and heap profiling against Worker Previews and Durable Object previews. By sending test traffic to a preview, invoking the profiling API, and retrieving a flamegraph, you can see which functions in a pull‑request consume the most resources without touching live traffic.

How Preview Profiling Works

Each preview deployment receives a unique identifier. When you request a profile, the platform records execution data for the latest preview of the specified worker. The result is a flamegraph that breaks down self‑time and memory allocation per function, allowing you to pinpoint hotspots such as a repeatedly instantiated Intl.NumberFormat object.

Practical Steps for Engineers

Typical workflow:

  1. Deploy a preview locally with npx wrangler preview or via CI.
  2. Generate steady load against the preview URL.
  3. Capture a 10‑second CPU or heap profile using the Cloudflare CLI:
cf previews deployments profile latest \
  --worker my-worker

The command returns a profile linked to the preview’s deployment ID. Review the flamegraph, modify the hottest function, and repeat until the self‑time no longer drops.

Architectural and Operational Implications

Because profiling occurs entirely within the preview environment, production latency and cost remain unchanged. This separation encourages a performance‑first mindset in code review pipelines and enables automated agents to iterate on optimisation without risking live traffic. The version‑specific IDs also make it possible to store profiling artifacts alongside build artefacts for audit or regression tracking.

From an operations perspective, teams can treat preview profiling as a lightweight, on‑demand alternative to full‑scale production observability. It reduces the need for long‑running synthetic load tests in production and can be integrated into pull‑request checks to enforce resource budgets.

Related CloudNinjas coverage: hands-on guides.

What This Means For Practitioners

Engineers should add a profiling step to their CI/CD flow for any worker that handles non‑trivial computation. Capture the deployment ID, record the top‑time functions, and enforce a threshold that triggers a review. Security‑focused teams can also use the isolation of previews to verify that performance tweaks do not unintentionally expose new attack surfaces, since the preview never touches production data. In short, preview profiling offers a low‑risk, high‑visibility feedback loop for CPU and memory optimisation before code lands in production.

Originally published atCloudflare Developer Platform