unix icon indicating copy to clipboard operation
unix copied to clipboard

Optimize serialization in eval_fork

Open jeroen opened this issue 6 years ago • 3 comments

library(ggplot2)
data(diamonds, package = "ggplot2")
get_diamonds <- function(){
  return(diamonds)
}

test_base <- function(){
  unserialize(serialize(get_diamonds(), NULL))
}

test_ascii <- function(){
  unserialize(serialize(get_diamonds(), NULL, ascii = TRUE))
}

test_dirk <- function(){
  RApiSerialize::unserializeFromRaw(RApiSerialize::serializeToRaw(get_diamonds()))
}

test_sys <- function(){
  sys::eval_safe(get_diamonds())
}

test_parallel <- function(){
  proc <- parallel::mcparallel(get_diamonds())
  out <- parallel::mccollect(proc)
  parallel::mccollect(proc)
  out[[1]]
}

t1 <- test_base()
t2 <- test_ascii()
t3 <- test_dirk()
t4 <- test_sys()
t5 <- test_parallel()
stopifnot(all.equal(t1, t2))
stopifnot(all.equal(t1, t3))
stopifnot(all.equal(t1, t4))
stopifnot(all.equal(t1, t5))


library(microbenchmark)
microbenchmark(
  base = test_base(),
  ascii = test_ascii(),
  dirk = test_dirk(),
  sys = test_sys(),
  parallel = test_parallel(),
  times = 10
)

jeroen avatar Mar 03 '18 14:03 jeroen