Chrome profiler. Why do functions sometimes stop for a while?

Here is an image of my web execution captured by Chrome Performance Devtools:

enter image description here

I notice that functions will stop many times at runtime when my web functions are stopped. Chrome performs some RegExp operations (as shown). I do not understand what it is and why this is happening. Please help explain, thanks.

Update: is a function that also executes in the same way:

enter image description here

+5
source share
1 answer

What do you describe

As you describe the problem, it looks like you think that the JavaScript virtual machine puts functions into standby mode (stopping them) during their execution (i.e. before they return) to do something else, and then resume functions.

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

What I see

VM performs:

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

Then the deepest function returns, and the called function returns, etc. etc., until fire returns, fireWith returned, a function whose name we cannot read is returned, and callback returns.

Then the virtual machine starts the RegExp function and calls the function called callback again, and it all starts again. In other words, the second column is with callback , and the rest is a new function call. Functions do not "ping for a short time": they are called several times.

I see this all the time in libraries that respond to events. Usually they iterate over event handlers to call them. Given a rather complex library, there is a sufficient amount of glue code that can be between the loop that calls the handlers and your own code, so there are many recurring calls that appear during profiling.

+5
source

Source: https://habr.com/ru/post/1271473/


All Articles