JavaScripts are executed with multi-thread parallely in Chrome browser?

3,236 views
Skip to first unread message

jjyoo

unread,
Nov 1, 2010, 10:48:48 PM11/1/10
to Chromium-dev

Dear all,

It may be an inane question.

But i need your answer for my question.

As described in the title,
JavaScripts in Chrome browser are executed with multi-thread parallely
in a multicore system?
If not, why it is difficult to do so?

Thank you in advance.

Peter Kasting

unread,
Nov 1, 2010, 11:07:49 PM11/1/10
to jeongj...@gmail.com, Chromium-dev
On Mon, Nov 1, 2010 at 7:48 PM, jjyoo <jeongj...@gmail.com> wrote:
JavaScripts in Chrome browser are executed with multi-thread parallely
in a multicore system?

Script runs in the renderer process.  There are generally multiple renderer processes when there are multiple tabs, so in this case, multiple pieces of script are run in parallel.

Script is not run multithreaded because the web execution environment generally assumes single-threadedness and not complying with this would break the web.

PK 

jjyoo

unread,
Nov 1, 2010, 11:58:01 PM11/1/10
to Chromium-dev

For examples, www.nytimes.com has about 30 JavaScripts.

Your answer means, although we have a multicore environment, the above
30 JavaScripts do not need to be executed in parallel (because of no
performance gain) due to the JavaScript's single-threadness?

or You mean, we cannot execute the 30 JavaScript in parallel because
we have difficulty in synchronization for shared data?

Thank you again.

On 11월2일, 오후12시07분, Peter Kasting <pkast...@chromium.org> wrote:

Mike Belshe

unread,
Nov 2, 2010, 12:03:47 AM11/2/10
to jeongj...@gmail.com, Chromium-dev
On Mon, Nov 1, 2010 at 8:58 PM, jjyoo <jeongj...@gmail.com> wrote:

For examples, www.nytimes.com has about 30 JavaScripts.

Your answer means, although we have a multicore environment, the above
30 JavaScripts do not need to be executed in parallel (because of no
performance gain) due to the JavaScript's single-threadness?

or You mean, we cannot execute the 30 JavaScript in parallel because
we have difficulty in synchronization for shared data?


It's not a "we have difficulty", its that the web has evolved over the past N years in its current form which is a single threaded form.  The scripts are not independent - they load into a single context, and they are order dependent.  You simply can't run them independently - there is inherently only one thread of control.

Now, recently, with HTML5, a new concept of "Web Workers" has been introduced.  For sites that wish to use multi-threaded or background workers, they can do so.  But, of course, they have to specifically design for this, and there are few examples of real usage other than the contrived cases.

Mike
 
Thank you again.

On 11월2일, 오후12시07분, Peter Kasting <pkast...@chromium.org> wrote:
> On Mon, Nov 1, 2010 at 7:48 PM, jjyoo <jeongjoon....@gmail.com> wrote:
> > JavaScripts in Chrome browser are executed with multi-thread parallely
> > in a multicore system?
>
> Script runs in the renderer process.  There are generally multiple renderer
> processes when there are multiple tabs, so in this case, multiple pieces of
> script are run in parallel.
>
> Script is not run multithreaded because the web execution environment
> generally assumes single-threadedness and not complying with this would
> break the web.
>
> PK

--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-dev

Alessandro Menezes

unread,
Nov 3, 2010, 7:43:00 AM11/3/10
to chromi...@chromium.org
Let's say you wrote a js file called myscript.js that depends on jquery. Then your webpage will look like this:

...
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="myscript.js"></script>
...

JQuery must be executed completely before your script starts, because you will use the stuff that it sets up for you.


2010/11/2 Mike Belshe <mbe...@google.com>

Ryan Shirley

unread,
Oct 29, 2013, 2:37:14 PM10/29/13
to chromi...@chromium.org, jeongj...@gmail.com, mbe...@google.com
Does chrome (or perhaps just chrome Canary 32.0.1685.0) use web workers to run some JS in parallel by default???  I was just testing an app in Canary and got unpredictable behaviour that looked like two functions were running in parallel.  Multiple refreshes of the page gave different (random) results.  I had two jQuery calls affecting the same element in my <script> on the page.  If I put the "second" call into a function after the first call, the random behaviour was gone.  Wierd!
Reply all
Reply to author
Forward
0 new messages