From francois.rousset at umontpellier.fr  Sun Nov 27 00:06:19 2016
From: francois.rousset at umontpellier.fr (=?UTF-8?Q?Fran=c3=a7ois_Rousset?=)
Date: Sun, 27 Nov 2016 00:06:19 +0100
Subject: [Rd] methods:::.selectSuperClasses and byte compilation
Message-ID: <a8968e28-e91a-1596-aa29-b1e807cd8344@umontpellier.fr>

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.



[Rd] methods:::.selectSuperClasses and byte compilation
=?UTF-8?Q?Fran=c3=a7ois_Rousset?=