Categories
josephscott

JavaScript Timing, Nothing Under 10ms

Tobie Langel pulled out an interesting little JavaScript nugget from the recent Background Music post on the Webkit/Safari Blog:

Some Web pages specify repeating timers with an extremely small timeout. In fact they often use the value 0 to mean “Fire as soon as you can.” Safari 2 does not throttle these timeouts, and so a poorly-constructed page that specifies a repeating timer under 10ms will actually hog a lot of CPU. Aggressive timers were actually a problem in Mozilla for a long time before being fixed, and they are currently a problem in Safari 2. WinIE, Firefox, and WebKit nightlies basically error-correct the badly constructed page and ignore timer values of < 10ms by changing them to be 10ms.

So don’t bother using setTimeout or setInterval for something less than 10ms.