
Intermediate workshop
Modern Angular November
Master the latest Angular features to build modern applications. Learn how to use standalone components, signals, the new inject method and much more.
Learn more
Understanding CPU profiling is easiest when you see it applied to real-world problems. This article walks through practical examples, starting with profiling a simple script and progressing to more complex builds that involve multiple threads and processes. You will see what current tools make possible, where their limitations appear, and find strategies to approach profiling with greater confidence in your own projects.
The following example demonstrates how to CPU profile a Node.js script using the --cpu-prof
Command:
This command will CPU profile the exmpl-script.jsCPU.<timestamp>.<pid>.<tid>.<seq>.cpuprofile
Output:
When a program creates multiple worker threads, you can use the --cpu-prof
Command:
node --cpu-prof --cpu-prof-dir=./cpu-prof-threads ./exmpl-create-threads.js
Output:
For a more real-life example, consider profiling the Angular framework's build process, which makes extensive use of worker threads to distribute work across its various build steps.
Command:
Output:
32 .cpuprofile
In the earlier examples, we could use relative paths because the CWD stayed the same. In practice, this is often not the case, and your files may end up in different folders depending on the current working directory.
You can profile multiple processes and store their results together in a single folder.
When doing this, make sure the output directory specified by --cpu-prof-dir
Command:
Note: The
environment variable is required to apply CPU profiling options to all child processes. This ensures each spawned process generates its own NODE_OPTIONSfile in the specified directory. Using only .cpuprofileas a command-ine argument will not work, as the --cpu-prof-dirflag may not be passed to child processes automatically. --cpu-prof
Output:
One practical real-world example is Nx for managing smart repositories. Building all projects in a monorepo with Nx spawns multiple processes for each project, along with potential threads depending on the build tool in use.
Command:
Output:
In practice, you would rarely profile that many processes at once. For example, Nx's TUI already provides a comprehensive overview of build times, and most other solutions include similar rough stats. From there, you can focus on the slowest part of the process and profile it in detail.
Currently, there is no officially supported tool for visualizing multiple CPU profiles generated during a single measurement. The most we can do with the default tools is apply a few best practices and follow established processes.
Less is more
Don't waste time creating 100 profiles that are hard to make sense of. Instead, run a measurement, open a few profiles, and work through them to form hypotheses. Once you have more clues, plan and run targeted measurements.
Rename your profiles
While building your understanding, it helps to rename the original profile file names to something more meaningful that you can remember and get back to later.
Isolate your measures
After you have identified the culprit, isolate the measurement to only what you need. For example, if you find a slow function, run just that function with --eval
Focus on quick wins and document your findings
Prioritize issues you understand, that have high impact, and are easy to fix. Avoid spending time on unclear, low-impact, or hard-to-guess problems.
Use the right tools
While there is no official tool for visualizing multiple CPU profiles, you can use @push-based/cpu-prof. It is a CLI that helps create and merge multiple CPU profiles into a single profile that the Chrome DevTools Performance Panel can read.
Exploring practical CPU profiling examples is one of the most effective ways to improve your performance analysis skills. Even though today’s tools have their limits, an organized and focused approach makes it much easier to cut through complexity and pinpoint what matters most. The profiling scenarios discussed above provide a strong foundation to start profiling your own projects and the confidence to keep exploring and optimizing for even better performance.

Intermediate workshop
Master the latest Angular features to build modern applications. Learn how to use standalone components, signals, the new inject method and much more.
Learn more
If Signals were Angular’s “aha!” moment, Zoneless is the “oh wow—this feels snappy” moment. With Angular v21, new apps use zoneless change detection by default. No more zone.js magic under the hood—just explicit, predictable reactivity powered by Signals.

Part 2 is a practical walkthrough to diagnose and speed up LCP. Learn to read CrUX trends, profile in Chrome DevTools, preload critical assets, use srcset, defer third-party scripts, and code-split Angular bundles to turn red LCP into green.

Deploy one Angular app for many clients with unique configs—without breaking SSR or DX. Here’s how to unlock dynamic configuration.

Largest Contentful Paint (LCP) is a Core Web Vital that shapes user perception of speed. This first part explains what LCP is why it matters for SEO and business, and how its phases affect site performance.

CPU profiles are more than flame charts—they’re structured JSON files. Learn how nodes, samples, and time deltas form the backbone of DevTools performance data.

Get deeper insights into your Node.JS performance. Learn how to master advanced CPU profiling with built-in tools, interpret process/thread IDs, and optimize using sampling intervals. Troubleshooting and real examples included.