Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome profiler - Why do functions sometimes stop for a little time?

Here is a picture of my web execution captured by Chrome Performance Devtools:

enter image description here

I notice that functions will be stopped many times during execution, when my web functions are stopped Chrome executes some RegExp operations (as shown in the picture). I don't understand what this is, and why it happens. Please help explain, thanks.

Update: here is a function which is also executed in the same manner:

enter image description here

like image 743
kkkkkkk Avatar asked Sep 03 '17 14:09

kkkkkkk


People also ask

What is scripting time in Chrome performance?

To be able to visually identify what was going on when you profiled your website, Timeline is painted in different colors. JavaScript execution time is marked in yellow and it's called Scripting. The purple area shows the Rendering and the green parts of the Timeline show the Painting process.

How do I debug Chrome performance?

To access the Performance tab, navigate to the website you want to profile, then open Chrome DevTools by right-clicking and selecting Inspect. Select the Performance tab inside Chrome DevTools. The easiest way to capture a performance profile is by clicking the Start profiling and reload page icon.

How do I troubleshoot JavaScript performance issues?

Google Chrome's DevTools is one of the best ways to measure JavaScript performance and debug any bottlenecks. You can open DevTools by running Google Chrome and then pressing Command+Option+I (Mac) or Control+Shift+I (Windows & Linux), or even just right-click and select Inspect.

How do I debug memory leak in Chrome?

The performance profiler in Chrome can visualize memory usage and graph it over time. To try this out, open the DevTools in Chrome and switch to the Performance tab. Note that we use an Incognito window when measuring performance.


1 Answers

What you describe

The way you describe the problem it sounds like you think the JavaScript virtual machine is putting the functions on hold (stopping them) while they are executing (i.e. before they return) to do something else and then resumes the functions.

The image you are showing does not suggest that at all to me.

What I'm seeing

The VM executes:

  • callback, which calls
  • some function whose name is hidden by a tooltip, which calls:
  • fireWith, which calls:
  • fire, which calls:
  • etc...

Then the deepest function returns, and the one that called it returns, and so on and so forth until fire returns, fireWith returns, the function whose name we cannot read returns, and callback returns.

Then the VM runs a RegExp function, and it calls a function named callback again, and the whole thing starts anew. In other words, the second column with callback and the rest is a new invocation of the functions. The functions are not "stop[ping] for a little time": they are called multiple times.

I see this all the time in libraries that respond to events. They typically will loop over event handlers to call them. Given a complex enough library, there'a fair amount of glue code that may sit between the loop that calls the handlers and your custom code so there's a lot of repetitive calls that show up in profiling.

like image 112
Louis Avatar answered Sep 30 '22 15:09

Louis