2011/1/14 foldi <[email protected]>:
> I'm trying to understand something about setInterval. When running the
> following in FF3, the time it takes to execute the interval's function
> does not take longer than the 30ms specified for the interval.
> However, it takes longer than 30ms to for the interval to run again.
> Where is the extra time going? Is there always some overhead to
> running a setInterval? Thanks [code]

In browsers Javascript is executed in an event loop. Consider a click event,
or a setTimeout/setInterval. These cases don't execute the code immediately,
they push it to the so-called event queue instead.

So when you click a button, what happens is that your click event enters
this queue and when nothing else is left the onclick handlers are
executed (in order).
Because of this, anything that gets to the queue before the click event has the
possibility to block. If the thread (the one and only) is blocked then
the upcoming actions
are delayed. In a case of a click event you experience a bit of
sluggishness in the UI.

So much is the case with setInterval. It tries to execute the given
function in time,
but if there's anything in the queue that may delay the execution of
your function.

I think setInterval itself is highly optimized, and as such shouldn't
cause any significant
overhead by itself.

- Balázs

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to