stefan-m-lenz / JuliaConnectoR

A functionally oriented interface for calling Julia from R
Other
100 stars 6 forks source link

Poor performance with Julia 1.9.1 on Windows #25

Closed stla closed 1 year ago

stla commented 1 year ago

Hello,

The code below performs the inversion of a 1000x1000 matrix. It takes 85 seconds with Julia. Is there a problem with v1.9.1? With previous versions it was fast.

library(JuliaConnectoR)

juliaModule <- "
module myJuliaModule
export mySolveJulia
export myProdJulia

function mySolveJulia(m)
  return inv(m)
end

function myProdJulia(m1, m2)
  return m1 * m2
end

end
"

. <- juliaEval(juliaModule)
myJuliaModule <- juliaImport(".myJuliaModule", all = FALSE)
mySolveJulia <- myJuliaModule$mySolveJulia

mySolveR <- function(x) solve(x)
set.seed(9392927)
N <- 1e3L
x1 <- matrix(rpois(N^2L, lambda = 10), N)

reps <- 2L
microbenchmark::microbenchmark(
  mySolveR(x1), 
  mySolveJulia(x1),
  times = reps
)

stopJulia()
stefan-m-lenz commented 1 year ago

Can you post a benchmark for a previous version where it was fast? I tested it with Julia 1.7.3 and Julia 1.9.1 and get the same (slow) speeds. This is expected, though, because the 1000x1000 matrix needs to be serialized and transferred to Julia, which takes time. The matrix inversion is already very optimized in R, so there isn't much room for improvement.

stla commented 1 year ago

It took 85 seconds for me. This is not expected, so I guess you didn't get such slowness. Did you test on Windows? Previously it took a couple of seconds.

stefan-m-lenz commented 1 year ago

I get the following times with Julia 1.9.1:

Unit: milliseconds
             expr        min         lq       mean     median        uq       max neval
     mySolveR(x1)   921.4297   921.4297   950.5004   950.5004   979.571   979.571     2
 mySolveJulia(x1) 23876.9331 23876.9331 23942.1428 23942.1428 24007.353 24007.353     2

And the following with Julia 1.7.3:

Unit: milliseconds
             expr        min         lq       mean     median         uq        max neval
     mySolveR(x1)   920.2987   920.2987   930.5349   930.5349   940.7711   940.7711     2
 mySolveJulia(x1) 23300.3275 23300.3275 23321.9664 23321.9664 23343.6052 23343.6052     2

So I don't see a significant difference between the version. I am also using Windows.

stla commented 1 year ago

Ok, that should be my laptop then.

Unit: seconds
             expr       min        lq       mean     median         uq
     mySolveR(x1)  2.651178  2.651178   2.751108   2.751108   2.851038
 mySolveJulia(x1) 97.121349 97.121349 101.392326 101.392326 105.663303
        max neval
   2.851038     2
 105.663303     2