0

I'm working on an R package that uses Rcpp and RcppArmadillo, and I'm trying to profile one of the main functions in the package to improve its runtime.

I'm using gperftools as recommended by Dirk and specifically as described in this blog post. The top two function calls (by number of profiling samples) are called _Rf_cons and _Rf_allocVector3.

Total: 1881 samples
     471  25.0%  25.0%      527  28.0% _Rf_cons
     308  16.4%  41.4%      309  16.4% _Rf_allocVector3

Does anyone know what these functions are, and where they might be called from in Rcpp code? I can't find any references to them via google or in the Rcpp GitHub repo.

Thanks!

Matt Stone
  • 185
  • 1
  • 1
  • 8
  • 2
    I think if you look at the (old) workshops / tutorials I also show some charts / tables based off the `gperftools` data. With R being a dynamiclly typed language with a garbage collector there is always _a lot_ else going on. In essence, you will see measurements for base R functions being called our code. Such is life. – Dirk Eddelbuettel Aug 02 '20 at 22:22
  • Thanks @DirkEddelbuettel! I have the profiling set up to isolate the C++ function (i.e., start_profiler(); call_Rcpp_fn(); stop_profiler()), so do you think that means these are likely to be associated with converting data in or out of base R? – Matt Stone Aug 02 '20 at 23:03
  • 2
    Yes, very good -- `gperftools` allow that. _But you still don't get Rcpp without R_ and that is exactly what you are seeing. The only way to profile your code "purely" is to ... have it hang off its own `main()` (which is often impractical...). – Dirk Eddelbuettel Aug 02 '20 at 23:07
  • Thanks! This was quite helpful. The function I'm profiling is an iterative algorithm; I had reduced the number of iterations for testing but I think I went too far. I increased the number of iterations and am seeing more reasonable results (mostly arma functions). I do have two follow up questions - 1) the top function call looks like a memory address. Is there any hope of parsing out what that corresponds to? 2) Would you have any suggestions for identifying what code would be calling Rcpp functions such as `internal::primitive_range_wrap__impl__nocast` or `Rcpp_ReleaseObject`? Thank you! – Matt Stone Aug 02 '20 at 23:42

0 Answers0