Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize serialization in eval_fork #1

Open
jeroen opened this issue Mar 3, 2018 · 3 comments
Open

Optimize serialization in eval_fork #1

jeroen opened this issue Mar 3, 2018 · 3 comments

Comments

@jeroen
Copy link
Owner

jeroen commented Mar 3, 2018

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 jeroen changed the title Optimize eval_fork Optimize serialization in eval_fork Mar 3, 2018
@jeroen
Copy link
Owner Author

jeroen commented Mar 3, 2018

OK the slowness is in unserialize.

@jeroen
Copy link
Owner Author

jeroen commented Mar 3, 2018

Adding an Rprintf() statement to OutBytesCB and the slowness is completely gone. Another Heisenbug.

@jeroen
Copy link
Owner Author

jeroen commented Apr 24, 2018

Maybe need to flush when writing to pipes?

@jeroen jeroen transferred this issue from jeroen/sys Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant