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

Ryosuke Niwa rniwa at webkit.org
Sat Dec 3 23:20:24 PST 2011

```I collected more data per Erik's suggestion:

Sample size: 42,000 - 1

n = Number of inserted nodes
1     2     7     6  100+     3   10+     5     4   20+
0.679 0.089 0.038 0.029 0.028 0.024 0.021 0.018 0.013 0.011

d = Number of ancestors of new parent
1   20+   10+     3     2     4     5     9     8     6
0.544 0.160 0.114 0.077 0.061 0.011 0.010 0.008 0.006 0.006

P(either but not both in document) = 0.625610133575

P(d=1 | n=1) ≈ 0.50007
P(parent not in document | n=1) ≈ 0.585
P(child not in document | n=1) ≈ 0.00681
P(either but not both in document | n=1) ≈ 0.589
P(either but not both in document) ≈ 0.626
P(n = 1, either but not both in document) ≈ 0.400
P(n = 1 | either but not both in document) ≈ 0.639

- Ryosuke

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.
>
> Best,
> Ryosuke Niwa
> Software Engineer