Microsoft says IE9 has Parallel Javascript Rendering and Execution
Asked Answered
G

1

7

The new JavaScript engine takes advantage of multiple CPU cores through Windows to interpret, compile, and run code in parallel. - http://technet.microsoft.com/en-us/library/gg699435.aspx

and

The Chakra engine interprets, compiles, and executes code in parallel and takes advantage of multiple CPU cores, when available. - http://msdn.microsoft.com/en-us/ie/ff468705.aspx

Wait, what?!? Does this mean we've got multi-threaded parallel JavaScript code execution (outside of web-workers) in IE9?

I'm thinking this is just a bad marketing gimmick but would like to see some more info on this. Maybe they mean different browser windows/tabs/processes can utilize multiple CPUs?

Goodard answered 7/6, 2011 at 14:34 Comment(6)
I have a feeling they mean "When you include multiple scripts in a page we will load and interpret them in parallel". Actual JavaScript execution is synchronous.Wellfavored
+1 to that, @Raynos. But they are stating that "execution/run" ("execution" and "run" are synonymous, right?) can happen in parallel.Goodard
@DavidMurdoch they can't. Half the internet would have broken and we would have noticed these race conditions in IE9 a long time ago. It's also understandable that they can run js code in parallel across tabs with one js thread per tab.Wellfavored
Surely Javascript being synchronous is only slightly more of a problem that most bits of assembly being synchronous? We have superscalar CPUs because it's often possible to spot when executing short bits of code in parallel that are semantically serial still produces the correct result. I guess in Javascript terms where almost everything (EDIT: in terms of, if you reviewed all code in the wild) is done via callback, it's about keeping track of which callbacks look at and/or modify which parts of global state and therefore which are actually completely independent.Mitchell
@Tommy, yah...sure, it would be nice...but I don't think they are doing that. Or maybe they just mean the code runs in parallel to code running on another machine. haha.Goodard
I think what they mean is that things like CSS changes driven by JavaScript code can be dealt with in parallel with script execution. It's all got to be done pretty carefully to avoid the "half the internet is broken" problem. Similarly, I don't think that they can process imported scripts in parallel. If I pull in jQuery and then my own code, clearly the first script has to run completely before mine can even be started.Hickox
M
3

Conclusions, based largely on the comments and hence provided as a community wiki answer so that this question ends up with an actual answer:

It's likely that Microsoft mean that the separate tasks of (i) interpreting and/or running; and (ii) compiling occur in parallel. It's probable that they've applied technology like Sun's old HotSpot JVM so that the Javascript virtual machine interprets code at the first instance because it can start doing that instantly. It also JIT compiles any code that appears to be used sufficiently frequently for doing so to be a benefit. It may even have different levels of compiler optimisation that it slowly dials up. In that case it may be using multiple cores to interpret or run one fragment of code while also compiling arbitrarily many others, or even while recompiling and better optimising the same piece of code that is being run.

However, it's also possible on a technical level that you could perform static analysis to determine when callbacks are mutually independent in terms of state, and allow those callbacks to execute in parallel if the triggering events prompted them to do so. In that way a Javascript virtual machine could actually interpret/run code in parallel without affecting the semantically serial nature of the language. Such a system would be logically similar to the operation of superscalar CPUs, albeit at a much greater remove and with significantly greater complexity.

Mitchell answered 7/6, 2011 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.