The speed of constructing a RooKeysPdf

I got a 50K entires of RooDataSet object to construct a RooKeysPdf object. Using the following construction method:

I spent about 3 mins to have it done. ( I used ACLiC complied library to run the code. )

Any expert knows how to speed this up?

Thanks in advance.


The construction of a RooKeysPdf is intrinsically expensive as you
are essentially constructing the sum of 50K Gaussian distributions
with varying with (determined from the local event density).

If you have a recent ROOT version (5.26), you can however persist
the entire RooKeysPdf in a file and read it back for future use. In that
case you don’t incur this startup overhead. See tutorial macros
rf502 and rf503 concerning persistence and reading back of pdfs.