How does the browser store JavaScript timer?

When the webpage moves to the background tab, the browser will throttle the timer.

This is not to require the browser to track a specific tab All timers?

If so, and at a high level, how is this achieved?

Or maybe the browser can limit the activity of the entire tab without considering any personal timers?

Specifically: Developers usually track timer IDs for various reasons. In some cases, isn’t this redundant? Suppose, the developer can’t just call a function that tells the browser “When you reach the timer in the event loop, do something special”

< /div>

When the webpage moves to the background tab, the browser will throttle the timer.

The browser will not specifically limit the timer in the background Each browser has an event loop for processing jobs in the queue. When the event is completed, it pulls the next item from the queue and processes it (it is different in the browser). When the browser enters the background or When the tab is not activated, the event loop is restricted. Each browser implements it in a different way again, and will restrict/remove the restriction in a different way.

For javascript timers, they are also in the event loop Processing, the result is a callback. This actually means that the timer in javascript will never be 100% accurate. If you set a timeout of 5000 milliseconds, it is likely that there will be a few milliseconds delay when the event loop reaches the processing timeout/interval, Also when the callback function is queued, the delay will add up. However, the event loop takes a long time to process it. Your 5000 milliseconds is more likely to add a few milliseconds in real time.

This is not asking the browser to track specific options All the timers for the card?

Yes, but the execution speed is as fast as the event loop allows the job to be processed.

Or, maybe the browser is able to limit it without considering any personal timers The activity of the entire tab?

No, the timer is affected by the event loop like any other code.

To summarize…

If the event loop is restricted, it will not be able to pass quickly Queue, so anything in the loop will be slower than usual, including timers.

Developers usually keep track of timer IDs for various reasons. In some cases, this is not superfluous NS? Suppose, the developer can’t just call a function that tells the browser “When you reach the timer in the event loop, do something special”

Yes, it may be redundant in some cases Yes, I often quote my timeouts or return them from functions but never do anything to the reference, at least what I need to do with it in the future.

I am not sure I understand 100% in the second part You. When you reach the timer in the event loop, the developer will do something special, especially to execute the callback at some point after the delay is over. In addition to that, you have no control other than queued code execution The loop itself.

When the webpage moves to the background tab, the browser will throttle the timer.

This is not a requirement Does the browser track all timers for a specific tab?

If so, and at a high level, how is this achieved?

Or maybe the browser can limit the activity of the entire tab without considering any personal timers?

Specifically: Developers usually track timer IDs for various reasons. In some cases, isn’t this redundant? Suppose, the developer can’t just call a function that tells the browser “when you reach the timer in the event loop, do something special”

When the webpage is moved to the background tab, the browser will throttle the timer.

The browser will not particularly limit the timer in the background. Each browser has an event loop. For processing jobs in the queue. When the event is completed, it pulls the next item from the queue and processes it (it is different in the browser). When the browser enters the background or the tab is not activated, the event loop will be restricted. Each browser implements it in a different way again, and will restrict/eliminate restrictions in a different way.

For javascript timers, they are also handled in the event loop and the result is a callback. This actually means javascript The timer in will never be 100% accurate. If you set a timeout of 5000 milliseconds, it is likely that there will be a few milliseconds delay when the event loop reaches the processing timeout/interval. Similarly, when the callback function is queued, the delay will add up but , The event loop takes a long time to process it. Your 5000 milliseconds is more likely to add a few milliseconds in real time.

Isn’t this asking the browser to keep track of all timers for a particular tab?

Yes, but the execution speed is as fast as the event loop allows the job to be processed.

Or, maybe the browser is able to limit it without considering any personal timers The activity of the entire tab?

No, the timer is affected by the event loop like any other code.

To summarize…

If the event loop is restricted, it will not be able to pass quickly Queue, so anything in the loop will be slower than usual, including timers.

Developers usually keep track of timer IDs for various reasons. In some cases, this is not superfluous NS? Suppose, the developer can’t just call a function that tells the browser “When you reach the timer in the event loop, do something special”

Yes, it may be redundant in some cases Yes, I often quote my timeouts or return them from functions but never do anything to the reference, at least what I need to do with it in the future.

I am not sure I understand 100% in the second part You. When you reach the timer in the event loop, the developer will do something special, especially to execute the callback at some point after the delay is over. In addition to that, you have no control other than queued code execution The loop itself.

Leave a Comment

Your email address will not be published.