<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 7, 2014 at 7:58 PM, Brady Eidson <span dir="ltr"><<a href="mailto:beidson@apple.com" target="_blank">beidson@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br><div><div>
On May 7, 2014, at 5:38 PM, Rik Cabanier <<a href="mailto:cabanier@gmail.com" target="_blank">cabanier@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 7, 2014 at 5:07 PM, Benjamin Poulain <span dir="ltr"><<a href="mailto:benjamin@webkit.org" target="_blank">benjamin@webkit.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On 5/7/14, 4:13 PM, Benjamin Poulain wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On 5/7/14, 3:52 PM, Filip Pizlo wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Exactly. Ben, Oliver, and others have made arguments against web<br>
workers. Rik is not proposing web workers. We already support them. The<br>
point is to give API to let developers opt into behaving nicely if they<br>
are already using web workers.<br>
</blockquote>
<br>
I have nothing against Web Workers. They are useful to dispatch<br>
background tasks.<br>
<br>
They are basically the Web equivalent dispatch_async() of GCD, which is<br>
already a very useful tool.<br>
<br>
What you are suggesting is useful for making Web Workers the tool to do<br>
high performance multi-thread computation.<br>
I don't think Web Workers are a great tool for that job at the moment. I<br>
would prefer something along TBB, GCD or something like that.<br>
<br>
<br>
For high performance computation, I think a more useful API would be<br>
something like TBB parallel_for with automatic chunking.<br>
It is actually had to do faster than that with the number of cores<br>
unless you know your task very very well.<br>
<br>
It would be a little more work for us, but a huge convenience for the<br>
users of Web Workers.<br>
</blockquote>
<br></div>
After chatting with Filip, it seems such a model is unlikely to happen anytime soon for JavaScript.<br>
<br>
In the absence of any tasks/kernels model, I am in favor of exposing a "good number of thread" API. It is definitely better than nothing.</blockquote><div><br></div><div>Do we know what this number would be? My guess would be the number of cores for "regular" systems...</div>
</div></div></div></blockquote><div><br></div></div></div></div><div>Define “regular” systems: </div></div></blockquote><div><br></div><div>"regular" systems are those were all running CPU's are of the same type. There are some exotic systems where some CPU's are much faster than others. I'm unsure what we should return there.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div> As Ryosuke mentioned, for systems that run on battery power (read: a vast majority of systems), keeping cores asleep to preserve battery life is often preferable to the user instead of waking up all available hardware and building up heat.</div>
</div></blockquote><div><br></div><div>Actually, spinning up more cores while on battery power might be more efficient.</div><div><br></div><div>I'm having a hard time finding good data, but take this chart for instance: <a href="http://www.anandtech.com/show/7903/samsung-galaxy-s-5-review/5" target="_blank">http://www.anandtech.com/show/7903/samsung-galaxy-s-5-review/5</a></div>
<div>Let's say you have a task that would take 1 core 4 seconds. This would mean 4 x 2612mw = 10456mw</div><div>Now if you can divide it over 4 cores: display = 854 (AMOLED), cpu core (simplified) = 2612 - 854 = 1758mw -> 854 + (4 x 1758mw) = 7886mw</div>
<div><br></div><div>On the desktop world, Intel Turbo boost [1] boosts single thread performance but at the expense of making the CPU run much hotter. Putting an even load will reduce power usage so the ratio of operator/watt will improve</div>
<div>There's a paper from NVidia that also describes this [2].</div><div><br></div><div>Just because you can break up the work, doesn't mean that you do MORE work.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div>Also, what type of cores? Physical cores, or logical cores?</div>
</div></div></blockquote><div><br></div><div>It would be logical cores. I think we're all compiling and running WebKit with hyper-threading turned on so it seems to work fine for parallel processing these days. </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div>Boris Zbarsky indicated that Firefox figures out how many workers should run concurrently. Maybe we can reuse that algorithm?</div></div></div></div></blockquote></div>I think it’s definitely worth looking in to.</div>
</div></blockquote><div><br></div><div>I got a reply from Boris and it's not what we're looking for:</div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote">
<div><span style="font-family:arial,sans-serif;font-size:13px">When a page tries to start a worker, we check whether that origin already has more than N workers running (where N is a pref, defaulting to 20). If it does, we just queue the worker until some of the extant ones finish. Otherwise we look for an idle thread, and if not found start a new one.</span><br style="font-family:arial,sans-serif;font-size:13px">
<br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">Idle threads that hang out for more than 30 seconds without doing anything get wound down.</span><br style="font-family:arial,sans-serif;font-size:13px">
</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div>Maybe we can keep the current patch that returns the number of available CPU's for now. [3]</div>
<div><br></div><div>1: <a href="http://www.intel.com/content/www/us/en/architecture-and-technology/turbo-boost/turbo-boost-technology.html?wapkw=turbo+boost" target="_blank">http://www.intel.com/content/www/us/en/architecture-and-technology/turbo-boost/turbo-boost-technology.html?wapkw=turbo+boost</a></div>
<div>2: page 12 of <a href="http://www.nvidia.com/content/PDF/tegra_white_papers/tegra-whitepaper-0911b.pdf" target="_blank">http://www.nvidia.com/content/PDF/tegra_white_papers/tegra-whitepaper-0911b.pdf</a></div><div>3: <a href="https://bugs.webkit.org/show_bug.cgi?id=132588" target="_blank">https://bugs.webkit.org/show_bug.cgi?id=132588</a></div>
<div><br></div></div></div></div>