Sub topic 4
Throttling the CPU and network to mimic real devices
This chapter assumes you can open the Performance panel and record a trace, and that you know the difference between a development and a production build. It covers how to slow your own machine down so a trace reflects what users on modest phones and weak connections experience.
Why your laptop misleads you
A developer machine usually has a fast multi-core CPU, plenty of memory, and a wired or strong Wi-Fi connection to a local server. A user on a mid-range phone may have a CPU that is four to six times slower on a single thread, and a mobile network with high latency.
Angular runs on the main thread. A change detection pass that takes 8 ms on your laptop can take 40 ms or more on a phone. That is long enough to miss a 16 ms frame budget and make scrolling or typing feel sluggish. If you profile without throttling, you may conclude that nothing is wrong.
Throttling does not make a trace more accurate in an absolute sense. It makes problems large enough to see, and it makes comparisons more realistic.
Where the throttling controls live
In the Performance panel, click the gear icon (Capture settings) in the toolbar. Two dropdowns matter here:
- CPU: No throttling, 4x slowdown, 6x slowdown, 20x slowdown, plus a calibrated option on recent Chrome versions.
- Network: No throttling, Fast 4G, Slow 4G, 3G, Offline, and custom profiles.
The Network panel has its own throttling dropdown in its toolbar. The two panels share the network setting, so changing it in one changes it in the other.
Newer Chrome versions also offer a CPU calibration step. It measures your machine and produces presets named after device classes, such as "low-tier mobile" and "mid-tier mobile". Use these when available, because a fixed "4x" means something different on a fast desktop than on a slow one.
How CPU throttling works
CPU throttling does not change your hardware. Chrome inserts pauses so that the main thread gets only a fraction of its normal processing time. A 4x slowdown means the same JavaScript takes roughly four times as long in wall-clock time.
Some things to know:
- It affects JavaScript execution, style calculation, and layout on the main thread.
- It does not slow down work that happens on the GPU or in other processes at the same rate, so rendering and decoding costs can look relatively smaller than they would on a real device.
- It cannot reproduce memory limits or thermal throttling on a real phone.
For these reasons, treat throttled results as a way to compare changes and to find problems. Use a real device to confirm anything important.
How network throttling works
Network throttling limits download throughput, upload throughput, and adds a fixed latency to each request. For example, a "Slow 4G" profile has a low bandwidth and several hundred milliseconds of added latency, which makes many small requests particularly expensive.
This matters for Angular because the first load involves a chain of work:
- The browser downloads
index.html. - It downloads the JavaScript bundles, such as
main.jsandpolyfills.js, plus any lazy chunks. - It parses and runs the code, and Angular bootstraps.
- The app fetches data from an API, then renders it.
Each step waits for the one before it. Latency is added at every link in that chain, so a slow network can turn a small number of sequential requests into a long delay.
Network throttling also affects the Performance panel's timeline. Gaps in the main thread track during a throttled load are often idle time spent waiting for the network, not slow code. Read the Network track above the flame chart before deciding that a gap is a problem in your code.
A recommended starting configuration
The following combinations work well for common questions.
| Question | CPU | Network |
|---|---|---|
| Is my interaction (click, typing, scroll) responsive? | 4x or 6x slowdown | No throttling |
| How long does the initial load take on a phone? | 4x slowdown | Fast 4G or Slow 4G |
| How does the app behave on a poor connection? | 4x slowdown | Slow 4G or 3G |
| Is my code the bottleneck, ignoring the network? | 4x or 6x slowdown | No throttling |
For interaction profiling, leave the network unthrottled. Otherwise, network waits will be mixed in with CPU cost and make the trace harder to read.
Recording a throttled trace
- Build and serve a production-like version of the app, as covered earlier in this tutorial.
- Open the Performance panel and click the gear icon.
- Choose a CPU setting and, if needed, a Network setting.
- For a load profile, use the reload button in the Performance panel, which records from the start of the page load. For an interaction profile, click Record, perform the interaction, then stop.
- Look for a yellow warning banner or an indicator on the panel tab showing that throttling is active.
Throttling settings stay on until you change them. It is easy to forget that a 6x slowdown is still set and then wonder why a later trace looks terrible. Check the settings at the start of each session.
Reading the effect in a trace
Suppose a list screen re-renders on every keystroke in a search box. Without throttling, the trace might show a task of about 12 ms after each key press. That is under a 16 ms frame, so the interaction feels fine and you may stop looking.
With a 6x CPU slowdown, the same task shows up at around 70 ms. In the flame chart, a task that is wider than 50 ms is marked as a long task with a red corner. Now the problem is clear, and you can zoom in to find that most of the time is in change detection and in a template method that filters the list.
Notice that the shape of the flame chart stays the same. The same functions appear in the same order, only wider. This is the property that makes throttling useful for comparisons. If a function accounts for 60% of the task unthrottled, it will account for about 60% when throttled.
Common errors
- Comparing traces recorded with different settings. A trace at 4x and a trace at no throttling cannot be compared. Record the before and after traces with identical throttling.
- Profiling a development build under throttling. Development mode adds extra checks, such as the second change detection pass that detects
ExpressionChangedAfterItHasBeenCheckederrors. Throttling multiplies that overhead too and distorts the picture. - Forgetting the cache. A throttled reload can hit the browser cache, which hides download cost. Tick "Disable cache" in the Network panel, or use a fresh profile, when you measure load.
- Blaming code for network waits. Idle gaps in a throttled load are usually waiting, not work.
- Trusting one run. Throttled traces still vary. Record at least three and compare typical values, not the best or worst.
- Leaving extensions on. Browser extensions add work to the main thread. Use an Incognito window with extensions disabled for cleaner traces.
Throttling and your own measurements
If you add User Timing marks, covered later in this tutorial, their durations also grow under throttling. This is useful. Record the same mark under the same throttling before and after a change, and compare the numbers in the Timings track.
Pick one throttling profile for a given investigation and write it down alongside your results, for example "Production build, 4x CPU, no network throttling, Disable cache on, 3 runs." Later chapters rely on this habit when you verify an optimization.
Exercise
You record a click interaction in the Performance panel with no throttling and see a 14 ms task, so you decide the interaction is fine. A colleague records the same interaction and sees a 90 ms task. Give two likely causes of the difference and one change to your recording setup that makes the two traces comparable.
Show answer
Likely causes: your colleague had CPU throttling (for example 6x slowdown) turned on, or they profiled a development build with extra checks while you profiled a production build. Browser extensions or a slower machine could also contribute. To make the traces comparable, both people should profile the same production-like build with the same CPU throttling setting (for example 4x), the same network setting, an Incognito window with extensions off, and the same interaction, then record several runs each.
Exercise
You throttle the network to Slow 4G and reload the page. The main thread track shows a long empty gap before the first scripting block. Is this evidence of slow Angular code? What would you check instead?
Show answer
No. An empty main thread gap during a throttled load usually means the browser is waiting for resources, not running code. Check the Network track and the Network panel waterfall to see which requests (HTML, main bundle, lazy chunks, API calls) are in flight during the gap, and look at their sizes and timing.