<br><br><div class="gmail_quote">On Fri, Nov 13, 2009 at 1:46 PM, Boris Zbarsky <span dir="ltr"><<a href="mailto:bzbarsky@mit.edu">bzbarsky@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On 11/12/09 9:21 PM, David Bruant wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I was waiting for Firefox to stop freezing on the HTML5 spec page (it<br>
freezes about one minute each time I visit the one-page version) and I<br>
tried to think of a way to "design" this page in a way that wouldn't<br>
freeze my browser.<br>
</blockquote>
<br></div>
Two easy ways to do this:<br>
<br>
1) Take out the script at the end of the page that goes and messes<br>
with the DOM.<br>
2) Fix the O(N^2) algorithm in the web browser that this script<br>
happens to trigger<br>
(<<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=526394" target="_blank">https://bugzilla.mozilla.org/show_bug.cgi?id=526394</a>>; should be<br>
checked in pretty soon unless something goes drastically wrong).<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
One good way I have found would be to cut the whole page into several<br>
parts (one the server side, what is already done in the multi-page<br>
version) and to launch several workers. Each worker gets one part of the<br>
whole page in the background and could give it to the browsing context<br>
which will append the right part at the right place.<br>
</blockquote>
<br></div>
I'm not sure what you mean, exactly... what would the worker "give", exactly?<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
But what is this "give" ? Without the DOM API, this "give" means<br>
"sending a string through the postMessage() method" and the "append"<br>
means "rightPlace.innerHTML = stringContainingAPartOfThePage".<br>
However, with the DOM API, each worker could build independantly its<br>
documentFragment, send it to the browsing context which will "append"<br>
(appendChild) it in the right place.<br>
</blockquote>
<br></div>
The problem here is that of a script making certain DOM mutations after the DOM is completely built and reflecting those mutations into the rendering tree, not of initial DOM construction.<br>
<br>
That is, even if this proposal were implemented it would not eliminate the hang you're seeing without item 2 above being addressed.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Building the page requires 3 main operations :<br>
- getting the content (can be parallelized with the workers which can<br>
make XMLHttpRequests)<br>
- building a DOM tree from the content<br>
- rendering (cannot be parallelized because must occur in the browsing<br>
context)<br>
</blockquote>
<br></div>
And in this case the slowness you seem to be trying to address is in the "rendering" part.<br><font color="#888888">
<br>
-Boris<br>
</font></blockquote></div><br><br>The reason WebWorkers don't have access to the DOM is concurrency. For example, to loop through a list of children I need to first read the number of childrens, then have a for loop which starts at 0 and ends at length-1. If you have two threads that can access the DOM concurrently, then one could change the number of children while the other was looping through the list, which would cause bugs in the program. The only way to fix this is to make the DOM a monitor or introduce semaphores, but then you would have to change the way the DOM is accessed in HTML5, breaking backwards compatibility, which is not a good idea. <br>
<br>A better solution to your problem is to load fragments of the entire document using AJAX and then insert those fragments into the main document, when they are needed. You rarely need to see the entire document at once anyways.<br>
<br>Marius Gundersen<br>