Run the following in content_shell with --run-layout-test to dump the layout object tree.
<!DOCTYPE html>
<div id="d">x</div>
<script>
for (var i=0; i<10; i++)
d.appendChild(document.createTextNode(" "));
</script>
We unnecessarily create LayoutText objects for all 10.
Did some analysis for this. According to canHaveWhitespaceChildren() we are skipping white space children only for some elements. So for others we go ahead and create LayoutText. And we try to merge the nodes in mergeNextSiblingNodesIfPossible (invoked from node::normalize), but i couldn't normalize being called from anywhere other than from v8. So when i called normalize from content it is infact removing all these text nodes. So should we do something like this normalization in the text layout construction itlsef?
No, you cannot modify the dom like that unless the author explicitly asks for it through normalize().
ecobos@ started on this in: https://codereview.chromium.org/2719993003/
Yeah, the short answer is that this happens to expose bugs like issue 648931 in a few more places, so we probably need to wait for the lazy whitespace re-attachment rune@ is working on, or disabling that optimization if we're in a shadow tree or something like that...
Comment 1 by eco...@igalia.com
, Jan 27 2017