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

.rang_query_sysreqs is kind of slow with Github packages #40

Closed
chainsawriot opened this issue Feb 13, 2023 · 6 comments
Closed

.rang_query_sysreqs is kind of slow with Github packages #40

chainsawriot opened this issue Feb 13, 2023 · 6 comments

Comments

@chainsawriot
Copy link
Collaborator

https://github.com/chainsawriot/rang/blob/22b30f31f302b75c691c77de713bd1b8461b8f72/R/resolve.R#L338-L341

Maybe a better approach is to separate Github and CRAN packages and do the query, rather than switch to safe when there is just one Github package (usually).

@schochastics
Copy link
Member

schochastics commented Feb 13, 2023

R> system.time(rang::resolve("schochastics/rtoot"))
   user  system elapsed 
  7.894   0.828  47.624 
R> system.time(rang::resolve("rtoot"))
   user  system elapsed 
  0.233   0.001   1.333 

That's actually quite substantial! Have you identified a bottleneck? I feel like it wasn't that slow a day ago or so. nope was slow before

@chainsawriot
Copy link
Collaborator Author

x <- resolve("schochastics/rtoot", get_sysreqs = FALSE)
system.time(.rang_query_sysreqs(x))
##   user  system elapsed 
##  3.601   0.371  30.717 
y <- resolve("rtoot", get_sysreqs = FALSE)
system.time(.rang_query_sysreqs(y))
##   user  system elapsed 
##  0.069   0.004   0.677 

@chainsawriot
Copy link
Collaborator Author

system.time(.system_requirements_github("schochastics/rtoot", os = "ubuntu-20.04"))
##   user  system elapsed 
##  0.205   0.008   1.339 

@schochastics The exact reason is that all CRAN packages are queried one by one when there is a Github package, rather than in one query as in the all-CRAN case.

@schochastics
Copy link
Member

@chainsawriot finally reached that conclusion too now.

I think we could speed it up by grouping the refs?

.query_sysreqs_safe_grps <- function(targets, os = "ubuntu-20.04") {
  grps <- list("cran" = c(), "github" = c())
  refs <- vapply(targets, .parse_pkgref, return_handle = FALSE, character(1))
  for (i in names(grps)) {
    grps[[i]] <- targets[refs == i]
  }

  tryCatch({
    cran_handles <- vapply(grps[["cran"]], .parse_pkgref, character(1), return_handle = TRUE, USE.NAMES = FALSE)
    output <- .system_requirements_cran(handle = cran_handles, os = os)
  }, error = function(e) {
    output <- .query_sysreqs_safe(targets = targets, os = os)
  })
  
  for (pkg in grps[["github"]]) {
    output <- c(output, .system_requirements_gh(.parse_pkgref(pkg), os))
  }
  return(unique(output))
}

targets <- c("github::schochastics/rtoot", "cran::tibble", "cran::vctrs", 
               "cran::glue", "cran::cli", "cran::rlang", "cran::pkgconfig", 
               "cran::pillar", "cran::utf8", "cran::magrittr", "cran::lifecycle", 
               "cran::fansi", "cran::jsonlite", "cran::httr", "cran::R6", "cran::openssl", 
               "cran::askpass", "cran::sys", "cran::mime", "cran::curl", "cran::dplyr", 
               "cran::tidyselect", "cran::withr", "cran::generics", "cran::clipr")

system.time(a <- .query_sysreqs_safe(targets))
   user  system elapsed 
  3.067   0.451  20.978 
system.time(b <- .query_sysreqs_safe_grps(targets))
   user  system elapsed 
  0.406   0.021   2.442 
sort(a)==sort(b)
[1] TRUE TRUE TRUE TRUE TRUE

The function can be easily adapted to include other refs.
Any potential caveats? If not, I could work this in

chainsawriot added a commit that referenced this issue Feb 13, 2023
@chainsawriot
Copy link
Collaborator Author

7bbf7a7

system.time(rang::resolve("schochastics/rtoot"))
##   user  system elapsed 
##  1.181   0.018   9.084 

Pre

system.time(rang::resolve("schochastics/rtoot"))
   user  system elapsed 
  4.419   0.387  38.502 

@schochastics
Copy link
Member

perfect :)

chainsawriot added a commit that referenced this issue Feb 13, 2023
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

2 participants