Re: Conditional branch in tree builder based on DOM state

On Fri, 2 Jan 2009, Henri Sivonen wrote:
> On Dec 25, 2008, at 12:59, Ian Hickson wrote:
> > On Tue, 9 Dec 2008, Henri Sivonen wrote:
> > 
> > > 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——".
> > [...]
> > 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).
> 
> It would add a boolean flag to each stack node. The main complication 
> seems to be the setting the flag, which is pretty tame. Granted, it does 
> change the nature of the stack nodes a bit, since so far they've been 
> immutable.
> 
> > 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.
> 
> This seems a lot more complicated than requiring all implementations to 
> maintain a flag on each stack node.

I still haven't added this, because there doesn't seem to be much interest 
in this beyond your request, and because I really do think that keeping 
extra state around is a lot more expensive than you suggest.

I don't think that synchronising is that complicated, as it is a 
relatively localised and well-understandable piece of code (though I admit 
the code wouldn't be trivial), and it has the advantage of only slowing 
down rare cases where there exists a script doing these crazy 
modifications _and_ the parser is threaded. Having extra state everywhere 
would mean (slightly) slowing down everyone in all cases.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Wednesday, 11 February 2009 09:28:15 UTC