Skip to content

Commit fbc59bb

Browse files
committed
Merge branch 'main' into pr/2614
2 parents 37bc76e + 79734ba commit fbc59bb

27 files changed

Lines changed: 266 additions & 130 deletions

File tree

microsoft-edge/devtools-guide-chromium/about-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Microsoft Edge DevTools includes the following tools.
5757
| **Network conditions** tool | Use the **Network conditions** tool to disable the browser cache, set network throttling, set the user agent string, and set Content-Encodings such as deflate, gzip, and br. | [Network conditions tool](network-conditions/network-conditions-tool.md) |
5858
| **Network Console** tool | Use the **Network Console** tool to make changes to network requests (network calls) to see why they fail. Change and replay any of the network requests, and make detailed network API calls. | [Network Console tool](network-console/network-console-tool.md) |
5959
| **Network request blocking** tool | Use the **Network request blocking** tool to test blocking network requests to a specified URL pattern and see how a webpage behaves. | [Network request blocking tool](network-request-blocking/network-request-blocking-tool.md) |
60-
| **Performance** tool | Analyze runtime performance, which is how your page performs when it's running, as opposed to loading. | [Get started analyzing runtime performance](evaluate-performance/index.md) |
60+
| **Performance** tool | Analyze runtime performance, which is how your page performs when it's running, as opposed to loading. | [Introduction to the Performance tool](evaluate-performance/index.md) |
6161
| **Performance monitor** tool | Provides a real-time view of the runtime performance of a webpage, to determine where performance problems come from, making a website run slowly. Finds whether problems are from high memory or CPU usage, too-frequent layout and style calculations, or too many DOM nodes and event listeners. | [Measure runtime performance of a page using the Performance monitor tool](performance-monitor/performance-monitor-tool.md) |
6262
| **Quick source** tool | Use the **Quick source** tool to display or edit source files when using a tool other than the **Sources** tool. | [Display or edit source files using the Quick source tool](quick-source/quick-source-tool.md) |
6363
| **Rendering** tool | Use the **Rendering** tool to see what your webpage looks like with different display options or vision deficiencies. | [Rendering tool, to see what a webpage looks like with different display options or vision deficiencies](rendering-tools/rendering-tool.md) |

microsoft-edge/devtools-guide-chromium/evaluate-performance/index.md

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: Get started analyzing runtime performance
2+
title: Introduction to the Performance tool
33
description: Tutorial about how to evaluate runtime performance in Microsoft Edge DevTools.
44
author: MSEdgeTeam
55
ms.author: msedgedevrel
66
ms.topic: conceptual
77
ms.prod: microsoft-edge
8-
ms.date: 11/22/2022
8+
ms.date: 2/22/2023
99
---
1010
<!-- Copyright Kayce Basques
1111
@@ -20,15 +20,14 @@ ms.date: 11/22/2022
2020
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2121
See the License for the specific language governing permissions and
2222
limitations under the License. -->
23-
# Get started analyzing runtime performance
23+
# Introduction to the Performance tool
2424

2525
_Runtime performance_ is how your page performs when it's running, as opposed to loading. The following tutorial teaches you how to use the DevTools **Performance** tool to analyze runtime performance.
2626

27-
In terms of the **RAIL** model, the skills you learn in this tutorial are useful for analyzing the Response, Animation, and Idle phases of your page.
27+
The skills you learn in this tutorial are useful for analyzing loading, interactivity, and visual stability of your web content, which are also key indicators for [Core Web Vitals](https://web.dev/vitals/). Each of the Core Web Vitals represents a distinct facet of the user experience, is measurable in the field, and reflects the real-world experience of a critical user-centric outcome. You can see these Core Web Vitals in the **Performance** tool.
2828

29-
See also [Optimize website speed using Lighthouse](../speed/get-started.md).
30-
31-
<!--todo: add rail link when section is ready -->
29+
See also:
30+
- [Optimize website speed using Lighthouse](../speed/get-started.md)
3231

3332

3433
<!-- ====================================================================== -->
@@ -38,22 +37,22 @@ In the following tutorial, you open DevTools on a "Sluggish Animation" demo page
3837

3938
1. Open the [Sluggish Animation](https://microsoftedge.github.io/Demos/devtools-performance-get-started/) demo page in your InPrivate tab or window. To do that, right-click the link and then select **Open link in InPrivate window**. You'll profile this page, which shows a variable number of icons moving up and down. For more information about InPrivate, see [Browse InPrivate in Microsoft Edge](https://support.microsoft.com/microsoft-edge/browse-inprivate-in-microsoft-edge-cd2c9a48-0bc4-b98e-5e46-ac40c84e27e2)
4039

41-
Note: The source for this demo is at [MicrosoftEdge / Demos > devtools-performance-get-started](https://github.com/MicrosoftEdge/Demos/tree/main/devtools-performance-get-started).
40+
Source code: [MicrosoftEdge / Demos > devtools-performance-get-started](https://github.com/MicrosoftEdge/Demos/tree/main/devtools-performance-get-started).
4241

4342

4443
<!--TODO: replace section when updated for Chromium-based Edge -->
4544

4645
<!-- You can view the source files for the "Sluggish Animation" demo page at the [MicrosoftEdge/Demos > devtools-performance-get-started](https://github.com/MicrosoftEdge/Demos/tree/main/devtools-performance-get-started) repo folder. -->
4746

48-
1. Press **Ctrl+Shift+I** (Windows, Linux) or **Command+Option+I** (macOS) to open DevTools.
47+
1. Press **Ctrl+Shift+I** (Windows, Linux) or **Command+Option+I** (macOS) to open DevTools:
4948

5049
![The demo on the left, and DevTools on the right](./index-images/evaluate-performance-get-started-side-by-side.png)
5150

52-
53-
For the rest of the following screenshots, DevTools is [undocked to a separate window](../customize/placement.md), to better focus on the contents.
51+
For the rest of the screenshots, DevTools is shown [undocked to a separate window](../customize/placement.md).
5452

5553

56-
### Simulate a mobile CPU
54+
<!-- ------------------------------ -->
55+
#### Simulate a mobile CPU
5756

5857
Mobile devices have much less CPU power than desktops and laptops. Whenever you profile a page, use CPU Throttling to simulate how your page performs on mobile devices.
5958

@@ -70,22 +69,24 @@ Mobile devices have much less CPU power than desktops and laptops. Whenever you
7069
If you want to ensure that pages work well on low-end mobile devices, set **CPU** to **6x slowdown**. The demo doesn't work well with 6x slowdown, so it just uses 4x slowdown for instructional purposes.
7170

7271

73-
### Set up the demo
72+
<!-- ------------------------------ -->
73+
#### Set up the demo
7474

7575
The following section lets you customize the demo to make sure that your experience is relatively consistent with the screenshots and descriptions.
7676

7777
1. Click the **Add 10** button until the blue icons move noticeably slower than before. On a high-end machine, you can click it about 20 times.
7878

7979
1. Click **Optimize**. The blue icons should move faster and more smoothly.
8080

81-
1. To better display a difference between the optimized and non-optimized versions, click the **Subtract 10** button a few times and try again. If you add too many blue icons, you could max out the CPU, and then you might not observe a major difference in the results for the two versions.
81+
1. To better display a difference between the optimized and unoptimized versions, click the **Subtract 10** button a few times and try again. If you add too many blue icons, you could max out the CPU, and then you might not observe a major difference in the results for the two versions.
8282

8383
1. Click **Un-Optimize**. The blue icons move slower and with more sluggishness again.
8484

8585

86-
### Record runtime performance
86+
<!-- ------------------------------ -->
87+
#### Record runtime performance
8788

88-
When you ran the optimized version of the page, the blue icons move faster. Why is that? Both versions are supposed to move the icons the same amount of space in the same amount of time. Take a recording in the **Performance** tool to learn how to detect the performance bottleneck in the non-optimized version.
89+
When you ran the optimized version of the page, the blue icons move faster. Why is that? Both versions are supposed to move the icons the same amount of space in the same amount of time. Take a recording in the **Performance** tool to learn how to detect the performance bottleneck in the unoptimized version.
8990

9091
1. In DevTools, click **Record** (![Record](./index-images/record-icon.png)). DevTools captures performance metrics as the page runs.
9192

@@ -116,7 +117,7 @@ Once you have a recording of the page's performance, you can assess the page's p
116117
![Hover on a frame](./index-images/evaluate-performance-performance-frame-hover.png)
117118

118119

119-
120+
<!-- ------------------------------ -->
120121
#### Bonus: Open the Frame Rendering Stats overlay
121122

122123
Another handy tool is the **Frame Rendering Stats** overlay, which provides real-time estimates for FPS as the page runs. The **Frame Rendering Stats** overlay is not required for this tutorial but may provide helpful insight.
@@ -132,7 +133,8 @@ Another handy tool is the **Frame Rendering Stats** overlay, which provides real
132133
1. When you are done reviewing the FPS data, clear the **Frame Rendering Stats** checkbox to hide the overlay.
133134

134135

135-
### Find the bottleneck
136+
<!-- ------------------------------ -->
137+
#### Find the bottleneck
136138

137139
After you verified that the animation isn't performing well, the next step is to answer the question "why?"
138140

@@ -170,7 +172,7 @@ After you verified that the animation isn't performing well, the next step is to
170172

171173
![The line of code that caused the forced layout](./index-images/evaluate-performance-sources-app-update.png)
172174

173-
The problem with the non-optimized code is that, in each animation frame, it changes the style for each icon, and then queries the position of each icon on the page. Because the styles changed, the browser doesn't know if each icon position changed, so it has to re-layout the icon in order to compute the new position.
175+
The problem with the unoptimized code is that, in each animation frame, it changes the style for each icon, and then queries the position of each icon on the page. Because the styles changed, the browser doesn't know if each icon position changed, so it has to re-layout the icon in order to compute the new position.
174176
<!--
175177
> To learn more, see [Avoid forced synchronous layouts](https://web.dev/avoid-large-complex-layouts-and-layout-thrashing/#avoid-forced-synchronous-layouts).
176178
-->
@@ -179,12 +181,77 @@ After you verified that the animation isn't performing well, the next step is to
179181
This article gives you a lot to learn. But now you have a solid foundation in the basic workflow for analyzing runtime performance. Good job.
180182

181183

182-
### Analyze the optimized version
184+
<!-- ------------------------------ -->
185+
#### Analyze the optimized version
183186

184187
Using the workflows and tools that you just learned, click **Optimize** on the demo to turn on the optimized code, take another performance recording, and then analyze the results. From the improved framerate to the reduction in events in the flame chart in the **Main** section, the optimized version of the app does much less work, resulting in better performance.
185188

186-
The optimized code uses a different sequence of actions to do less work. Note that this code could be made even faster by only using properties that only affect compositing, instead of manipulating the `top` property of every icon.
187-
<!-- > For more information, see [Use transform and opacity changes for animations](https://web.dev/stick-to-compositor-only-properties-and-manage-layer-count/#use-transform-and-opacity-changes-for-animations). todo: add rendering section when available -->
189+
190+
<!-- ------------------------------ -->
191+
#### Unoptimized version
192+
193+
Compare this snippet of JavaScript from the unoptimized version of the app:
194+
195+
```javascript
196+
var pos = m.classList.contains("down")
197+
? m.offsetTop + distance
198+
: m.offsetTop - distance;
199+
if (pos < 0) pos = 0;
200+
if (pos > maxHeight) pos = maxHeight;
201+
m.style.top = pos + "px";
202+
if (m.offsetTop === 0) {
203+
m.classList.remove("up");
204+
m.classList.add("down");
205+
}
206+
if (m.offsetTop === maxHeight) {
207+
m.classList.remove("down");
208+
m.classList.add("up");
209+
}
210+
```
211+
212+
The above code snippet runs on every frame of the browser rendering loop, for each blue icon on the page. The `m` variable references a single blue icon.
213+
214+
In this unoptimized version, we create a `pos` variable that's set to the current position of the icon, to which we add some distance. The current position of the icon is read by using `m.offsetTop`.
215+
216+
After making sure that the icon is still within the bounds of the page, we set its new position by using `m.style.top`, which sets inline styles on the element.
217+
218+
Finally, we read `m.offsetTop` again, to adjust the direction of the icon.
219+
220+
221+
<!-- ------------------------------ -->
222+
#### Optimized version
223+
224+
The optimized code uses a different sequence of actions to do less work. Here is the same snippet of JavaScript from the optimized version of the app:
225+
226+
```javascript
227+
var pos = parseInt(m.style.top.slice(0, m.style.top.indexOf("px")));
228+
m.classList.contains("down") ? (pos += distance) : (pos -= distance);
229+
if (pos < 0) pos = 0;
230+
if (pos > maxHeight) pos = maxHeight;
231+
m.style.top = pos + "px";
232+
if (pos === 0) {
233+
m.classList.remove("up");
234+
m.classList.add("down");
235+
}
236+
if (pos === maxHeight) {
237+
m.classList.remove("down");
238+
m.classList.add("up");
239+
}
240+
```
241+
242+
In the optimized version, we first set the value of the `pos` variable by reading `m.style.top` instead of using `m.offsetTop`. Using the element's inline style is faster, because reading `m.offsetTop` forces the browser engine to know where all the elements are on the page, which requires the engine to recalculate the styles and the layout.
243+
244+
We then set the new position of the icon, like done in the unoptimized version, but we don't read `m.offsetTop` again (like done in the unoptimized version) to adjust the icon's direction.
245+
246+
The unoptimized code reads and writes the position of the icon from two different places, forcing the browser to recalculate the style and layout on each frame. The optimized version, however, writes and reads the position of the icon in the inline styles only.
247+
248+
249+
<!-- ------------------------------ -->
250+
#### Further possible optimizations
251+
252+
This code could be made even faster by using CSS properties that only require the browser to do compositing, rather than layout. Instead of manipulating the `top` property, which forces the browser to run its layout code again, using the `transform` property would allow the browser to consider each icon as an individual layer, and then display these layers in the correct positions by re-compositing the final image. For example, instead of using `m.style.top = pos + "px";`, we can use `m.style.transform = translateY(pos + "px,");`.
253+
254+
To learn more, see [Use transform and opacity changes for animations](https://web.dev/stick-to-compositor-only-properties-and-manage-layer-count/#use-transform-and-opacity-changes-for-animations).
188255

189256

190257
<!-- ====================================================================== -->
@@ -193,13 +260,15 @@ The optimized code uses a different sequence of actions to do less work. Note th
193260
<!--The foundation for understanding performance is the RAIL model. The RAIL model teaches you the performance metrics that are most important to your users.
194261
To learn more, see [Measure Performance With The RAIL Model](https://web.dev/rail/). -->
195262

196-
To get more comfortable with the **Performance** tool, practice makes perfect. Try profiling your pages and analyzing the results. If you have any questions about your results, use the **Send Feedback** icon, press **Alt+Shift+I** (Windows, Linux) or **Option+Shift+I** (macOS), or [file an issue on the MicrosoftEdge / DevTools repo](https://github.com/MicrosoftEdge/DevTools/issues). Include screenshots or links to reproducible pages, if possible.
263+
To get more comfortable with the **Performance** tool, practice profiling your pages and analyzing the results.
264+
265+
If you have any questions about your results, use the **Send Feedback** icon, press **Alt+Shift+I** (Windows, Linux) or **Option+Shift+I** (macOS), or [file an issue on the MicrosoftEdge / DevTools repo](https://github.com/MicrosoftEdge/DevTools/issues):
197266

198267
![The **Feedback** icon in the Microsoft Edge DevTools](./index-images/evaluate-performance-feedback-icon.png)
199268

200-
<!-- To really become an expert in runtime performance, you must learn how the browser translates HTML, CSS, and JS into pixels on a screen. The best place to start is the [Rendering Performance](https://web.dev/rendering-performance/). [The Anatomy Of A Frame](https://aerotwist.com/blog/the-anatomy-of-a-frame/) dives into even more detail. -->
269+
Include screenshots or links to reproducible pages, if possible.
201270

202-
Last, there are many ways to improve runtime performance. This article focused on one particular animation bottleneck to give you a focused tour of the **Performance** tool, but it's only one of many bottlenecks you may encounter. <!-- The rest of the Rendering Performance series has a lot of good tips for improving various aspects of runtime performance, such as: -->
271+
There are many ways to improve runtime performance. This article focused on one particular animation bottleneck to give you a focused tour of the **Performance** tool, but it's only one of many bottlenecks you may encounter. <!-- The rest of the Rendering Performance series has a lot of good tips for improving various aspects of runtime performance, such as: -->
203272

204273
<!--
205274
* [Optimize JavaScript execution](https://web.dev/optimize-javascript-execution/)

microsoft-edge/devtools-guide-chromium/evaluate-performance/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ms.date: 05/04/2021
2424

2525
This page is a comprehensive reference of DevTools features that are related to analyzing performance.
2626

27-
For a step-by-step tutorial on how to analyze the performance of a page using the **Performance** tool, see [Get started analyzing runtime performance](index.md).
27+
For a step-by-step tutorial on how to analyze the performance of a page using the **Performance** tool, see [Introduction to the Performance tool](index.md).
2828

2929

3030
<!-- ====================================================================== -->

microsoft-edge/devtools-guide-chromium/evaluate-performance/selector-stats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ As a general rule, if you find a CSS selector that took the browser a long time
5555
<!-- ====================================================================== -->
5656
## See also
5757

58-
* [Get started analyzing runtime performance](./index.md) - An introduction to analyzing runtime performance in DevTools.
58+
* [Introduction to the Performance tool](./index.md) - An introduction to analyzing runtime performance in DevTools.
5959
* [Performance features reference](./reference.md) - Covers many of the features in the **Performance** tool.
6060
* [The truth about CSS selector performance](https://blogs.windows.com/msedgedev/2023/01/17/the-truth-about-css-selector-performance/)

microsoft-edge/devtools-guide-chromium/evaluate-performance/unminify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ For details, see [Map the processed code to your original source code, for debug
8989
<!-- ====================================================================== -->
9090
## See also
9191

92-
* [Get started analyzing runtime performance](index.md) - An introduction to analyzing runtime performance in DevTools.
92+
* [Introduction to the Performance tool](index.md) - An introduction to analyzing runtime performance in DevTools.
9393
* [Performance features reference](reference.md), - A reference for many of the features offered in the Performance tool.

0 commit comments

Comments
 (0)