Rcpp11 / attributes

Standalone implementation of Rcpp attributes.
Other
3 stars 1 forks source link

Make RNGScope optional #29

Open romainfrancois opened 10 years ago

romainfrancois commented 10 years ago

The production of

Rcpp::RNGScope __rngScope;

in the generated code should be optional. There are many cases when we are not going to generate random values. But we pay for this all the time, even though it is cheap. cheap is more expensive than free.

I think it should be disabled by default, and then we can ask for it with e.g. [[export(random=TRUE)]]

jjallaire commented 10 years ago

I would argue that random = TRUE should be the default. Several reasons:

(1) Without it users will inadvertently use random functions without RNGScope and not realize there is a problem (they may or may not have ever read the documentation indicating that this is an issue to be concerned with).

(2) I recall measuring the performance cost at ~ 2ms. I think the cases where this actually matters are going to be rare.

(3) Since the Rcpp default is to use RNGScope, users migrating code from Rcpp to Rcpp11 will get different results and not know why.

romainfrancois commented 10 years ago

I can sympathize with the concerns. About 2) However cheap it might be, why should I pay it if I'm not using it. I kind of miss the days when we had to explicitely create the RNGScope.

With minimal testing, you'd quickly realize about 1.

And for (3), I'd rather not be dictated by Rcpp choices (good or bad).

Perhaps we can leave export untouched for Rcpp compatibility and have variants. The question then is how to name an attribute that does the same as export but without the RNGScope bit.

Alternatively, we could have control parameters, either as parameters of sourceCpp and compileAttributes or special attributes to handle defaults. Soemthing like this:

// [[ defaults( random = FALSE ) ]]