Reputation: 7738
Here is a picture of my web execution captured by Chrome Performance Devtools:
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:
Upvotes: 7
Views: 895
Reputation: 151370
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.
The VM executes:
callback
, which callsfireWith
, which calls:fire
, which calls: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.
Upvotes: 5