Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Internals: At what interval does the event loop run?

This is a question about JavaScript internals.

Lets say I have 10 async tasks that all take x number of seconds to run. Whilst waiting for a response the script is idle.

In the background the JavaScript engine is asking "Is there anything on the task queue". To my understanding this is a loop. Hence, event loop. I know in Node this is implemented with Libuv. I've read this article which explains a little: https://nikhilm.github.io/uvbook/basics.html

Do JavaScript engines place any restriction on how often this event loop runs in order to balance out performance of the application? Does it run at a set interval?

If I'm off with anything, please correct me. I was purely interested at what interval this event loop runs.

like image 355
BugHunterUK Avatar asked Sep 07 '25 08:09

BugHunterUK


1 Answers

There is no loop per se in the JavaScript side. There is one in libuv though. Basically libuv will wait until the closest timer hits or an i/o operation happens. Then it will fire a callback in C, which calls the C++ function Node passed and then this triggers JavaScript code to be executed.

Have a look at this presentation, specially the section starting at slide 33.

like image 128
saghul Avatar answered Sep 10 '25 03:09

saghul