[Rd] methods:::.selectSuperClasses and byte compilation
François Rousset
francois.rousset at umontpellier.fr
Sun Nov 27 00:06:19 CET 2016
Dear R-devel list,
Running the following example on a recent R-devel (here, 2016-11-22
r71672) shows that the byte compiler can cause some significant
performance drops (here, computation time increasing from 0.01s to 0.31s
...)
=================================
library(Matrix)
someMatrix <- new("dtCMatrix", i= c(1L, 0:3), p=c(0L,0L,0:2, 5L), Dim =
c(5L, 5L),
x = rep(1, 5), diag = "U")
compiler::enableJIT(3) ## R-devel default
system.time(replicate(100,Matrix::crossprod(someMatrix))) ## slow !
compiler::enableJIT(0)
system.time(replicate(100,Matrix::crossprod(someMatrix))) ## fast
==================================
By tracing compiler::cmpfun, I found that the reason may be that
invoking Matrix::crossprod calls methods:::.selectSuperClasses which
creates and runs the following function
function (exti) {!isVirtualExt(exti) && length(exti at by) == 0 && exti at simple}
and thus that this function is byte-compiled each time Matrix::crossprod
is called.
Is there a straightforward way for users / R package writers to avoid
such problems, or shouldn't it be fixed in the R sources ?
Thanks,
F.
More information about the R-devel
mailing list