Skip to content

Commit

Permalink
Stop memoization from reacting to spurious changes
Browse files Browse the repository at this point in the history
to function internals. Related: #345
  • Loading branch information
wlandau-lilly committed Nov 9, 2018
1 parent f5af6be commit a63f1dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ VignetteBuilder: knitr
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- **Large speed boost**: reduce repeated calls to `parse()` in `code_dependencies()`.
- **Large speed boost**: change the default value of `memory_strategy` (previously `pruning_strategy`) to `"speed"` (previously `"lookahead"`).
- Compute a special data structure in `drake_config()` (`config$ordinances`) just to store the code analysis results. This is an intermediate structure between the workflow plan data frame and the graph. It will help clean up the internals in future development.
- Improve memoized preprocessing: deparse all the functions in the environment so the memoization does not react so spurious changes in R internals. Related: #345.
- Remove strict dependencies on packages `evaluate`, `fs`, `future`, `magrittr`, `parallel`, `R.utils`, `stats`, and `stringi`.
- Deprecate the `force` argument to `make()` and related functions.
- Change the name of `prune_envir()` to `manage_memory()`.
Expand Down
38 changes: 27 additions & 11 deletions R/create_drake_ordinances.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ create_drake_ordinances <- function(
trigger = parse_trigger(trigger = trigger, envir = envir),
globals = sort(c(plan$target, ls(envir = envir, all.names = TRUE)))
)
imports <- cdn_prepare_imports(config)
imports <- cdo_prepare_imports(config)
imports_kernel <- cdo_imports_kernel(config, imports)
import_ordinances <- memo_expr(
cdn_analyze_imports(config, imports),
cdo_analyze_imports(config, imports),
config$cache,
imports
imports_kernel
)
command_ordinances <- memo_expr(
cdn_analyze_commands(config),
cdo_analyze_commands(config),
config$cache,
config$plan,
config$trigger,
Expand All @@ -37,10 +38,10 @@ create_drake_ordinances <- function(
c(import_ordinances, command_ordinances)
}

cdn_prepare_imports <- function(config) {
cdo_prepare_imports <- function(config) {
console_preprocess(text = "analyze environment", config = config)
imports <- as.list(config$envir)
cdn_unload_conflicts(
cdo_unload_conflicts(
imports = names(imports),
targets = config$plan$target,
envir = config$envir,
Expand All @@ -50,7 +51,7 @@ cdn_prepare_imports <- function(config) {
imports[import_names]
}

cdn_unload_conflicts <- function(imports, targets, envir, verbose) {
cdo_unload_conflicts <- function(imports, targets, envir, verbose) {
common <- intersect(imports, targets)
if (verbose & length(common)) {
message(
Expand All @@ -61,7 +62,22 @@ cdn_unload_conflicts <- function(imports, targets, envir, verbose) {
remove(list = common, envir = envir)
}

cdn_analyze_imports <- function(config, imports) {
cdo_imports_kernel <- function(config, imports) {
out <- lightly_parallelize(
X = imports,
FUN = function(x) {
if (is.function(x)) {
x <- deparse(x)
}
x
},
jobs = config$jobs
)
names(out) <- names(imports)
out[sort(names(out))]
}

cdo_analyze_imports <- function(config, imports) {
names <- names(imports)
console_many_targets(
targets = names,
Expand All @@ -88,7 +104,7 @@ cdn_analyze_imports <- function(config, imports) {
out
}

cdn_analyze_commands <- function(config) {
cdo_analyze_commands <- function(config) {
console_many_targets(
targets = config$plan$target,
pattern = "analyze",
Expand All @@ -115,15 +131,15 @@ cdn_analyze_commands <- function(config) {
)
out <- lightly_parallelize(
X = ordinances,
FUN = cdn_prepare_ordinance,
FUN = cdo_prepare_ordinance,
jobs = config$jobs,
config = config
)
names(out) <- config$plan$target
out
}

cdn_prepare_ordinance <- function(ordinance, config){
cdo_prepare_ordinance <- function(ordinance, config){
ordinance$deps_build <- command_dependencies(
command = ordinance$command,
exclude = ordinance$target,
Expand Down

0 comments on commit a63f1dc

Please sign in to comment.