[whatwg] Stat. on frequency of node insertion without children

Yehuda Katz wycats at gmail.com
Sat Dec 3 18:26:28 PST 2011


Yehuda Katz
(ph) 718.877.1325


On Fri, Dec 2, 2011 at 11:24 PM, Ryosuke Niwa <rniwa at webkit.org> wrote:

> Hi all,
>
> Several days ago, we had a discussion about improving DOM performance on
> #whatwg where I hypothesized that most of nodes inserted by methods like
> insertBefore, appendChild, etc... don't have any children, and therefore we
> can bypass checks for HIERARCHY_REQUEST_ERR by just checking the nullity of
> firstChild.
>
> To confirm my hypothesis, I made a custom build of WebKit and collected
> statistics, and here's the result. The sample size is 3585 DOM API calls
> while browsing facebook, twitter, gmail, google+, and webkit's bugzilla.
>
> <number of nodes inserted per DOM API call> <percentage>
>   1 52.887%
>   2 9.763%
>   3 6.416%
> 100+ 5.132%
>   7 4.686%
>   6 2.566%
>   5 2.120%
>   4 1.339%
>   8 1.032%
>   9 0.837%
>
> i.e. 52.9% of all inserted nodes don't have any children.
>

At least when using jQuery, it's decently common to do something like
$("#el").append("<p>hi</p>"), which can quite easily create children.
jQuery internally creates the nodes in question, inserts them into a
documentFragment, and then inserts the documentFragment, so at least in the
documentFragment case, I would expect it to be extremely common for
children to be present.


>
> Best,
> Ryosuke Niwa
> Software Engineer
> Google Inc.
>



More information about the whatwg mailing list