title: setInterval running slow on Safari
body: <p>I'm working on an HTML5 canvas-based game, and have hit a bit of a problem in Safari (on Windows).</p>
  
  <p>The game runs nicely in Firefox and Chrome, and even IE, but on Safari everything moves really slowly.</p>
  
  <p>The main game loop is triggered by calling a method (update) using setInterval with a timing of 50ms (20Hz).</p>
  
  <p>I set up some console timers to check how long update took to run, thinking maybe it was exceeding the 50ms and causing problems, but it typically only took between 6 and 20ms, so plenty of room to spare.</p>
  
  <p>I then tried a simple counter to see how many times update got hit, and timed it for 10 seconds.  In that time it should execute 200 times, but instead was only executing about 60 times! Yikes!  No wonder it's running about 1/3 the speed it should be.</p>
  
  <p>I then emptied out the update method, leaving just the console count in place, and ran it again.  This time in 10 seconds it ran around 200 times as it should.</p>
  
  <p>Has anybody else had this problem?  Is there some kind of workaround, or possibly just something I am doing wrong?</p>
  
  <p>UPDATE:</p>
  
  <p>I've had a chance to test it on Safari on the Mac and it ran beautifully. Seems to just be a poor implementation of setInterval on the Windows version of Safari.</p>
  
  <p>I found this interesting demo, which shows the lag of setInterval...
  <a href="http://www.goat1000.com/2011/03/23/how-accurate-is-window.setinterval.html" rel="nofollow">http://www.goat1000.com/2011/03/23/how-accurate-is-window.setinterval.html</a></p>
  
  <p>It's a pretty simple example which has very basic computational needs, but even so it doesn't take long for the lag to show up in Windows Safari. You can imagine then how much worse it is for a complex graphical game.</p>