4 ms·
Until "web workers" are generally supported by common browsers, there is no way to run more than on bit of Javascript at a time in any given tab. As all the cod
by dspillett 15y ago
Until "web workers" are generally supported by common browsers, there is no way to run more than on bit of Javascript at a time in any given tab. As all the code is running in a single thread it will only use one CPU core (or if the scheduler bounces the browser process between cores it will use at most one core/second worth of CPU resource per second).
Depending on the how much cross talk there would be between the threads, web workers might not be adequate for some algorithms anyway as the message passing (the only way web workers can communicate, there is no "shared memory" access or other such short cuts to communication) could add noticeable latency. Caveat: I've not used them for anything myself so I don't know if any such latency is large enough to be an issue.
You can create multi-threaded code using web workers, but you exclude your app from browsers that don't support them. The major laggard on the desktop is IE, which is due to gain support for them in version 10. As far as I know the only current mobile browser that supports them is Safari under iOS5, apparently they were present in Android's browser but removed/disabled in recent releases.
- starwed 15y agoI'd assume Firefox Mobile supports them, since AFAIK they use exactly the same JS engine as regular Firefox.
- eik3_de 15y agoThank you for your thorough answer!
- aapl 15y agoThere is also WebCL, an effort underway to put OpenCL in the browser, and River Trail, an experiment to execute subset of JavaScript using OpenCL as a backend. I don't know how difficult it is to write a CPU compute device driver, so I don't know if WebCL will become a viable general stategy for multicore execution in a browser though.