<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>6998</bug_id>
          
          <creation_ts>2006-02-01 01:51:30 -0800</creation_ts>
          <short_desc>setTimeout(0) tight loop uses almost all CPU (need 10ms minimum for timeout?)</short_desc>
          <delta_ts>2008-09-29 15:24:22 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>420+</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>EasyFix, HasReduction</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>6628</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Sjoerd Mulder">sjoerdmulder</reporter>
          <assigned_to name="Darin Adler">darin</assigned_to>
          <cc>ap</cc>
    
    <cc>darin</cc>
    
    <cc>ddkilzer</cc>
    
    <cc>mjs</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>30927</commentid>
    <comment_count>0</comment_count>
    <who name="Sjoerd Mulder">sjoerdmulder</who>
    <bug_when>2006-02-01 01:51:30 -0800</bug_when>
    <thetext>The following code shows a simple loop which uses the setTimeout function to call the same function again, but without the performance drain of a while(true) loop.

function testTimeout() {
    setTimeout(testTimeout,0);
}

This works perfectly in Internet Explorer, Firefox and Opera. Taking almost 0% CPU-time. But Safari / Webkit takes 100% of CPU-time... This is a very serious performance problem. With setTimeout on 1 ms, it takes 25% which is still unacceptable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30928</commentid>
    <comment_count>1</comment_count>
      <attachid>6177</attachid>
    <who name="Sjoerd Mulder">sjoerdmulder</who>
    <bug_when>2006-02-01 01:52:18 -0800</bug_when>
    <thetext>Created attachment 6177
Testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30937</commentid>
    <comment_count>2</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2006-02-01 04:17:47 -0800</bug_when>
    <thetext>Confirmed bug on Safari 2.0.3 (417.8) and nightly r12504 on Mac OS X 10.4.4.

Test case consumes close to 100% CPU while the test is running.  Changing to P1 due to poor performance.

Adding HasReduction and HitListCandidate keywords.  Do we need a &quot;Performance&quot; keyword, too?
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30940</commentid>
    <comment_count>3</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2006-02-01 04:37:21 -0800</bug_when>
    <thetext>Blocker (&quot;parent&quot;) is on HitList, so removing HitListCandidate keyword.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30954</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-02-01 05:58:02 -0800</bug_when>
    <thetext>I&apos;m wondering what the explanation of low processor usage in other browsers is - actually, 100% processor usage looks like what is explicitly requested here (similar to a while(true) loop). Probably I&apos;m missing something.

BTW, Win32 timers wouldn&apos;t honor a timeout lower than a certain threshold (normally, 10 ms). Maybe Firefox emulates this behavior?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30975</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2006-02-01 09:20:35 -0800</bug_when>
    <thetext>I&apos;m not sure why this is a bug. Are we supposed to run JavaScript programs more slowly so they don&apos;t take so much CPU time? The program asks to run as fast as possible.

Maybe we need a version that counts how many times it runs, then we can write a bug for those other browsers about the fact that they run setTimeout too slowly?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30976</commentid>
    <comment_count>6</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2006-02-01 09:21:31 -0800</bug_when>
    <thetext>The 10ms minimum of Windows is probably the issue here.

We can easily hobble our timers so they can&apos;t fire in less than 10ms -- presumably that will fix this.

This is not a P1 bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30984</commentid>
    <comment_count>7</comment_count>
      <attachid>6194</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-02-01 10:43:08 -0800</bug_when>
    <thetext>Created attachment 6194
count the number of ticks in 1 second

Indeed, Firefox and Opera both limit their timers to 10ms, even on the Mac.

For 10ms timers, Safari seems to take slightly more CPU time than Firefox, but less than Opera (respectively 3.7%, 3.1%, 6.5% on my dual G4, as observed with top).

Given the workaround of explicitly using a 10ms timeout, should this issue be removed from the list of Backbase blockers?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30985</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2006-02-01 10:47:46 -0800</bug_when>
    <thetext>It&apos;s trivial to put in a 10ms minimum -- I&apos;ll do that now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30995</commentid>
    <comment_count>9</comment_count>
    <who name="Dave Hyatt">hyatt</who>
    <bug_when>2006-02-01 13:37:54 -0800</bug_when>
    <thetext>Yeah all the other browsers have a 10ms minimum.  Guess we should too.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31090</commentid>
    <comment_count>10</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2006-02-02 09:32:16 -0800</bug_when>
    <thetext>I recommend that the application in question be changed to only request 10 ms if it doesn&apos;t really want to be called as often as possible.

I&apos;ve now made WebKit standard and unwilling to fire timers faster than that, but it&apos;s really a mistake to ask for timeout 0 if you don&apos;t want to be called as fast as you can.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31123</commentid>
    <comment_count>11</comment_count>
    <who name="Sjoerd Mulder">sjoerdmulder</who>
    <bug_when>2006-02-03 00:09:42 -0800</bug_when>
    <thetext>Verified to be fixed on nightly build r12540</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35546</commentid>
    <comment_count>12</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2006-03-08 10:35:27 -0800</bug_when>
    <thetext>FYI, it seems that MapQuest uses the same technique, which was the cause of &lt;rdar://problem/4289661&gt; MapQuest.com map in Safari uses all CPU, but not on Internet Explorer.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>6177</attachid>
            <date>2006-02-01 01:52:18 -0800</date>
            <delta_ts>2006-02-01 01:52:18 -0800</delta_ts>
            <desc>Testcase</desc>
            <filename>timeout.html</filename>
            <type>text/html</type>
            <size>1098</size>
            <attacher name="Sjoerd Mulder">sjoerdmulder</attacher>
            
              <data encoding="base64">PCEtLSAtLT4KPCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgU3Ry
aWN0Ly9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL3hodG1sMS9EVEQveGh0bWwxLXN0cmljdC5k
dGQiPgo8aHRtbCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCIgeG1sbnM6Yj0i
aHR0cDovL3d3dy5iYWNrYmFzZS5jb20vYiIgeG1sbnM6cz0iaHR0cDovL3d3dy5iYWNrYmFzZS5j
b20vcyI+Cgk8aGVhZD4KCQk8bWV0YSBodHRwLWVxdWl2PSJjb250ZW50LXR5cGUiIGNvbnRlbnQ9
InRleHQvaHRtbDsgY2hhcnNldD1pc28tODg1OS0xIiAvPgoJCTx0aXRsZT5QZXJmb3JtYW5jZSBw
cm9ibGVtIFNhZmFyaSAvIFdlYmtpdDwvdGl0bGU+CgkJPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFz
Y3JpcHQiPgoKCQkJZnVuY3Rpb24gdGVzdFRpbWVvdXQoKSB7CgkJCQlzZXRUaW1lb3V0KHRlc3RU
aW1lb3V0LDApOwoJCQl9CgoJCTwvc2NyaXB0PgoJPC9oZWFkPgoJPGJvZHkgb25sb2FkPSJ0ZXN0
VGltZW91dCgpOyI+CgkJPGgyPlBlcmZvcm1hbmNlIG9mIDxjb2RlPnNldFRpbWVvdXQ8L2NvZGU+
IGZ1bmN0aW9uIGluIFNhZmFyaSAvIFdlYmtpdDwvaDI+CgkJPHA+VGhlIGZvbGxvd2luZyBjb2Rl
IHNob3dzIGEgc2ltcGxlIGxvb3Agd2hpY2ggdXNlcyB0aGUgPGNvZGU+c2V0VGltZW91dDwvY29k
ZT4gZnVuY3Rpb24gdG8gY2FsbCB0aGUgc2FtZSBmdW5jdGlvbiBhZ2FpbiwgYnV0IHdpdGhvdXQg
dGhlIHBlcmZvcm1hbmNlIGRyYWluIG9mIGEgPGNvZGU+d2hpbGUodHJ1ZSk8L2NvZGU+IGxvb3Au
PC9wPgoJCTxwPjxwcmU+ZnVuY3Rpb24gdGVzdFRpbWVvdXQoKSB7PGJyIC8+CglzZXRUaW1lb3V0
KHRlc3RUaW1lb3V0LDApOzxiciAvPgp9PC9wcmU+PC9wPgoJCTxwPlRoaXMgd29ya3MgcGVyZmVj
dGx5IGluIEludGVybmV0IEV4cGxvcmVyLCBGaXJlZm94IGFuZCBPcGVyYS4gVGFraW5nIGFsbW9z
dCAwJSBDUFUtdGltZS4gQnV0IFNhZmFyaSAvIFdlYmtpdCB0YWtlcyAxMDAlIG9mIENQVS10aW1l
Li4uIFRoaXMgaXMgYSB2ZXJ5IHNlcmlvdXMgcGVyZm9ybWFuY2UgcHJvYmxlbS48L3A+Cgk8L2Jv
ZHk+CjwvaHRtbD4KCgoK
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>6194</attachid>
            <date>2006-02-01 10:43:08 -0800</date>
            <delta_ts>2006-02-01 10:43:08 -0800</delta_ts>
            <desc>count the number of ticks in 1 second</desc>
            <filename>timeout.html</filename>
            <type>text/html</type>
            <size>1254</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">PCEtLSAtLT4KPCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgU3Ry
aWN0Ly9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL3hodG1sMS9EVEQveGh0bWwxLXN0cmljdC5k
dGQiPgo8aHRtbCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCIgeG1sbnM6Yj0i
aHR0cDovL3d3dy5iYWNrYmFzZS5jb20vYiIgeG1sbnM6cz0iaHR0cDovL3d3dy5iYWNrYmFzZS5j
b20vcyI+Cgk8aGVhZD4KCQk8bWV0YSBodHRwLWVxdWl2PSJjb250ZW50LXR5cGUiIGNvbnRlbnQ9
InRleHQvaHRtbDsgY2hhcnNldD1pc28tODg1OS0xIiAvPgoJCTx0aXRsZT5QZXJmb3JtYW5jZSBw
cm9ibGVtIFNhZmFyaSAvIFdlYmtpdDwvdGl0bGU+CgkJPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFz
Y3JpcHQiPgoJCQkKCQkJdmFyIGNvdW50OwoJCQkKCQkJZnVuY3Rpb24gdGVzdFRpbWVvdXQoKSB7
CgkJCQkrK2NvdW50OwoJCQkJc2V0VGltZW91dCh0ZXN0VGltZW91dCwwKTsKCQkJfQoJCQkKCQkJ
ZnVuY3Rpb24gcmVwb3J0KCkgewoJCQkJYWxlcnQoIlRoZSB0aW1lciBoYXMgZmlyZWQgIiArIGNv
dW50ICsgIiB0aW1lcy4iKTsKCQkJfQoKCQk8L3NjcmlwdD4KCTwvaGVhZD4KCTxib2R5IG9ubG9h
ZD0iY291bnQ9MDsgdGVzdFRpbWVvdXQoKTsgc2V0VGltZW91dChyZXBvcnQsIDEwMDApOyI+CgkJ
PGgyP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