I'm currently playing with the idea of using IFRAMEs to implement a very simple multithreading engine. However my initial results are showing me that running in threads is slower than just running in a single thread.
My test is:
Single Thread
var start = new Date().getTime();
for (var i = 0; i < 300; i++) { /* Do costly processor operations */ }
debug('Took: ' + new Date().getTime() - start);
Multiple Threads
var start = new Date().getTime();
// In thread 1
for (var i = 0; i < 100; i++) { /* Do costly processor operations */ }
// In thread 2
for (var i = 100; i < 200; i++) { /* Do costly processor operations */ }
// In thread 3
for (var i = 200; i < 300; i++) { /* Do costly processor operations */ }
// In a callback in the original FRAME (thread)
debug('Took: ' + new Date().getTime() - start);
So as can be seen, I'm just splitting the work load amongst IFRAMEs (Note code above is only to give a better picture of what I am doing, it is not working code).
So I'm thinking that even using FRAMEs FireFox still has only one JS engine? Is this assumption correct? (rendering my research stupid), Are other browsers different?
Doing a quick googles I got this article: http://codediaries.blogspot.com/2009/12/real-javascript-multithreading-using.html
However the performance improvements achieved here are more than likely just doing parallel http requests rather than processing power.
Thanks for your insights.
Guido
Multithreading in JavaScript is the real right now. You can offload your work into multiple threads and share memory between them.
To sum up the other answers: No, iFrames usually run in the same thread/process as the main page.
js uses two kinds of threads: a main thread handled by the event loop and several auxiliary threads in the worker pool.
Multi-threading is a process that contains multiple threads within a single process. Here each thread performs different activities. For example, we have a class and this call contains two different methods, now using multithreading each method is executed by a separate thread.
Check out the HTML5 Web Workers Standard to see what JavaScript threading should look like. This is implemented in Firefox 3.5, Safari 4, and Chrome 3, but not IE. If you're willing to require a plugin for IE users and older browsers, check out Google Gears WorkerPool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With