W3C home > Mailing lists > Public > public-html@w3.org > December 2008

Re: Conditional branch in tree builder based on DOM state

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 25 Dec 2008 10:59:49 +0000 (UTC)
To: Henri Sivonen <hsivonen@iki.fi>
Cc: HTMLWG WG <public-html@w3.org>
Message-ID: <Pine.LNX.4.62.0812251055270.24109@hixie.dreamhostps.com>
On Tue, 9 Dec 2008, Henri Sivonen wrote:
> 
> We had a meeting about moving parsing off the main thread in Gecko. The 
> idea is to make the tree builder output a sequence of tree mutations on 
> a dedicated thread and to actuate the mutations on the main thread.
> 
> It is then a problem if the sequence of mutations is conditional on 
> information read synchronously from the DOM. There is one place in the 
> HTML5 parsing algorithm where this problem arises and cannot be remedied 
> by deferring the conditional check itself to the mutation actuation 
> time: step 7.5. of the adoption agency algorithm. The changes to the 
> internal state of the tree builder depend on whether a node has 
> children.
> 
> The problem would go away if instead of checking whether the node has 
> children in the DOM, there were a 'has children' flag on the tree 
> builder stack tracking whether the node has *parser-inserted* children.
> 
> The spec change suggestion, therefore, is making step 7.5. of the AAA 
> read "If node has any *parser-inserted* children, perform a shallow 
> clone of node——".

I'm vaguely convinced that this wouldn't introduce the possibility of 
crashers in weird cases with hostile scripts, but as I was looking at this 
a second concern came up.

While what you describe would make your particular implementation strategy 
easier, it would in fact complicate implementations that support script 
and operate on the DOM directly (i.e. all script-aware implementations 
today).

Instead, I recommend passing along an _assertion_ along with the 
mutations, along the lines of "these elements have children" and "these 
elements don't have children", which the main thread can quickly check. If 
the assertions turn out to be false, which will only happen in rare caes, 
then the thread can synchronise with the main thread, getting itself 
updated on what nodes have children, and then try again from that point.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Thursday, 25 December 2008 11:00:24 UTC

This archive was generated by hypermail 2.3.1 : Monday, 29 September 2014 09:39:00 UTC