Skip to content

Commit

Permalink
Speed up dependency graph construction
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jun 11, 2024
1 parent 812541e commit b087656
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.7.0.9001
Version: 1.7.0.9002
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# targets 1.7.0.9001 (development)
# targets 1.7.0.9002 (development)

* Use `bslib` in `tar_watch()`.
* Speed up `target_upstream_edges()` and `pipeline_upstream_edges()` by avoiding data frames until the last minute (17% speedup for certain kinds of large pipelines).

# targets 1.7.0

Expand Down
10 changes: 8 additions & 2 deletions R/class_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ pipeline_targets_only_edges <- function(edges) {

pipeline_upstream_edges <- function(pipeline, targets_only = TRUE) {
edge_list <- map(pipeline$targets, ~target_upstream_edges(.x))
edges <- do.call(rbind, edge_list)
from <- map(edge_list, ~.x$from)
to <- map(edge_list, ~.x$to)
from <- unlist(from, recursive = FALSE, use.names = FALSE)
to <- unlist(to, recursive = FALSE, use.names = FALSE)
edges <- data_frame(from = from, to = to)
edges <- if_any(targets_only, pipeline_targets_only_edges(edges), edges)
edges <- edges %|||% data_frame(from = character(0), to = character(0))
if (ncol(edges) < 2L) {
edges <- data_frame(from = character(0), to = character(0))
}
rownames(edges) <- NULL
edges
}
Expand Down
2 changes: 1 addition & 1 deletion R/class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ target_upstream_edges <- function(target) {
name <- target_get_name(target)
from <- c(name, target$command$deps)
to <- rep(name, length(from))
data_frame(from = from, to = to)
list(from = from, to = to)
}

target_update_queue <- function(target, scheduler) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ tar_test("target_downstream_nonbranching()", {
tar_test("target_upstream_edges()", {
skip_cran()
x <- target_init(name = "x", expr = quote(a + b))
e <- remove_loops(target_upstream_edges(x))
e <- remove_loops(as.data.frame(target_upstream_edges(x)))
expect_true(is.data.frame(e))
expect_equal(dim(e), c(3L, 2L))
expect_equal(unique(e$to), "x")
Expand Down

0 comments on commit b087656

Please sign in to comment.