HTML5 Web Workers need access to the DOM. And IE9 support
forums.whatwg.org
forums.whatwg.org
If you have a loop where you are setting and reading dom values, then that loop should be protected from other scripts modifying the dom, and hence there's a good chance one thread will have to halt making the web-workers pointless.
What happens if a DOM object has JavaScript values attached to it (bad practice but can happen), does the web-worker have access to these? If not then each web-worker will need a separate dom representation possibly creating a huge overhead.
The best way to take advantage of multi core processors is to allow each thread to have largely their own local memory and pass messages asynchronously between them, most architectures short of this will suffer greatly.
If not, having concurrent access to the dom is an extremely hard problem and would mostly likely have developers writing extremely inefficient code as the dom api would then need to manage transactions, whereas its usually best to figure out how to collect you changes into a large single edit.
Username here: roschdal. Username there: AndreasRosdal. Roschdal here has freeciv in their profile, and AndreasRosdal mentions freeciv.
In this setup, the current implementation of workers would simply be that the "main" thread has exclusive access to the entire DOM tree. It could be implemented and dropped in, and existing code would continue to work identically and uninterrupted.
But yes. Access to all DOM? PITA.
And sure, I'd like IE9 support too. And a pony.
The most important focus when writing commonly-labeled "HTML5" apps should be performance, for now at least. We are, at long last, overcoming the click-fetch-wait style of interaction with Web data; the dynamic nature of its replacement is a key feature, and the influx of performance-constrained rich-web devices need to support complex dynamic apps too.
So, I think we need to rethink the roles of common Web technologies. The DOM is no place for state; it should be treated more as an interface layer than a representation of data. JavaScript engines are tuned enough, and the basic architecture for extremely rich apps is in place, we just need to use our tools intelligently as implementors.
Web Workers are great because they let us break our computation out to something separate from the front end, without incurring the performance penalty of always having the DOM around.
Message passing to a front end that does the drawing is a reasonable design, and I think that this is a correct choice. Of course, if somebody could propose a design where multiple threads have access to the DOM without overhead, then I'd like that along with my unicorn too.
Web Workers intentionally can't share state and can only communicate via messages. AFAIK the only JavaScript engine that offers threadsafe access to objects is Rhino.