Yegor
Yegor

Reputation: 21

Window.setTimeout(f, 0) waits a lot when browser (Chrome) idles

I am analyzing performance of existing UI application using Chrome developer tool and have noticed a really strange behavior - from time to time (about 5-10%) browser just idles before executing the script from setTimeout(). I've googled a lot, and I've found a lot of answers that browser puts the script into the end of queue, so it waits until all other tasks are finished.

Yes, but it waits a lot more! From 10ms to 800ms more!

Chrome performance tool

Image

The code which sets this timeout looks pretty much like: y.setTimeout(a, 0)

Upvotes: 1

Views: 81

Answers (1)

Yegor
Yegor

Reputation: 21

Found an answer in related question: this happens when tab is inactive, because timers in inactive tabs fire once a second, so waiting "overhead" is floating from 0 to 1 second. Feels like not a real performance problem for users, but a real problem for our performance measurements...

Upvotes: 1

Related Questions