Skip to content

Make RNGScope optional #29

Open
Open

Description

@romainfrancois

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)]]

Activity

  1. jjallaire commented on Jun 23, 2014

    @jjallaire

    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.

  2. romainfrancois commented on Jun 23, 2014

    @romainfrancois
    ContributorAuthor

    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 ) ]]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions