Per Paul Irish: "inside ve.dm.MWBlockImageNode.static.toDataElement is some call that ends up calling jQuery.filter... I'm not sure what the filtering is for but because the DOM is SO HUGE this takes a long time.". Later: "yep, the cost is enormous".
This seems to be due to several .children() calls:
$imgWrapper = $figure.children( 'a, span' ).eq( 0 ), $img = $imgWrapper.children( 'img' ).eq( 0 ), $caption = $figure.children( 'figcaption' ).eq( 0 ),
Why is this so expensive? Surely the DOM being huge shouldn't matter for .children()? Or does the <figure> in question have an insane number of direct children? I checked the Parsoid DOM for Barack Obama, and all of the <figure>s on that page have exactly 2 children. This seems like a bug in jQuery / Sizzle perhaps?
Ori tells me this is due to a bug in Sizzle where setDocument is called and expensive processing is performed pretty much every time jQuery is used on a document that isn't window.document. I'll tally how often setDocument is called and try to reduce this number by reducing jQuery usage on foreign documents in VE.