Discussion:
[Rcpp-devel] Rcpp_fast_eval
Iñaki Úcar
2018-06-09 11:39:48 UTC
Permalink
Hi all,

I've followed with interest the development of the new evaluation API.
Now that it's finally merged, I was testing it. Perhaps I'm mistaken,
but shouldn't we expect a performance improvement in code such as the
following?

Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void old_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)

Rcpp::sourceCpp(code='
#define RCPP_PROTECTED_EVAL
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void new_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)

func <- function() 1
system.time(old_api(func, 1e5))
system.time(new_api(func, 1e5))

Regards,
Iñaki
Kevin Ushey
2018-06-10 00:15:37 UTC
Permalink
I think this is mostly because we still haven't ported the majority of
usages of Rcpp_eval() to the new Rcpp_fast_eval(), so by default users are
still getting the slower Rcpp_eval(). Compare e.g.

Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void Rcpp_eval_old(SEXP expr, int n) {
for (int i = 0; i < n; i++)
Rcpp_eval(expr, R_GlobalEnv);
}'
)

Rcpp::sourceCpp(code='
#define RCPP_PROTECTED_EVAL
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
void Rcpp_eval_new(SEXP expr, int n) {
for (int i = 0; i < n; i++)
Rcpp_fast_eval(expr, R_GlobalEnv);
}')

system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))
system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
user system elapsed
1.198 0.003 1.203
system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))
user system elapsed
0.118 0.034 0.151


We'll take a closer look next week.
Hi all,
I've followed with interest the development of the new evaluation API.
Now that it's finally merged, I was testing it. Perhaps I'm mistaken,
but shouldn't we expect a performance improvement in code such as the
following?
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void old_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)
Rcpp::sourceCpp(code='
#define RCPP_PROTECTED_EVAL
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void new_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)
func <- function() 1
system.time(old_api(func, 1e5))
system.time(new_api(func, 1e5))
Regards,
Iñaki
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Iñaki Úcar
2018-06-10 07:53:48 UTC
Permalink
Understood, thanks, Kevin and Qiang, for your response. Those numbers
are really impressive!, so special kudos to Lionel, Luke and everyone
involved in this new evaluation path for their efforts.

Looking forward to seeing these usages ported to the new
Rcpp_fast_eval. This will be a *huge* performance improvement for my
simulator, which compulsorily needs to make an intensive use of R
function evaluation from C++.

Iñaki
I think Kevin is right.
The Rcpp Function is still using the old API: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/Function.h#L82
Post by Iñaki Úcar
system.time(old_api(func, 1e5))
user system elapsed
1.025 0.000 1.025
Post by Iñaki Úcar
system.time(new_api(func, 1e5))
user system elapsed
0.025 0.000 0.025
I believe this is what Inaki expected.
Best wishes,
Qiang Kou
Post by Iñaki Úcar
I think this is mostly because we still haven't ported the majority of usages of Rcpp_eval() to the new Rcpp_fast_eval(), so by default users are still getting the slower Rcpp_eval(). Compare e.g.
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void Rcpp_eval_old(SEXP expr, int n) {
for (int i = 0; i < n; i++)
Rcpp_eval(expr, R_GlobalEnv);
}'
)
Rcpp::sourceCpp(code='
#define RCPP_PROTECTED_EVAL
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void Rcpp_eval_new(SEXP expr, int n) {
for (int i = 0; i < n; i++)
Rcpp_fast_eval(expr, R_GlobalEnv);
}')
system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))
Post by Kevin Ushey
system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
user system elapsed
1.198 0.003 1.203
Post by Kevin Ushey
system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))
user system elapsed
0.118 0.034 0.151
We'll take a closer look next week.
Post by Kevin Ushey
Hi all,
I've followed with interest the development of the new evaluation API.
Now that it's finally merged, I was testing it. Perhaps I'm mistaken,
but shouldn't we expect a performance improvement in code such as the
following?
Rcpp::sourceCpp(code='
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void old_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)
Rcpp::sourceCpp(code='
#define RCPP_PROTECTED_EVAL
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void new_api(Function func, int n) {
for (int i=0; i<n; i++) func();
}'
)
func <- function() 1
system.time(old_api(func, 1e5))
system.time(new_api(func, 1e5))
Regards,
Iñaki
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Iñaki Úcar
http://www.enchufa2.es
@Enchufa2
Loading...