tidymodels / dials

Tools for creating tuning parameter values
https://dials.tidymodels.org/
Other
111 stars 26 forks source link

return early when possible in `check_for_unknowns()` #306

Closed simonpcouch closed 10 months ago

simonpcouch commented 1 year ago

Closes #305.

Since quote(unknown()) is a "call", is.atomic() on quote(unknown()) or any object containing it will be FALSE. This saves a good bit of time:

x <- c(1, unknown())

bench::mark(
  map_is_unknown_val = any(map_lgl(x, dials:::is_unknown_val)),
  is_atomic = !is.atomic(x)
) %>%
  select(expression, median, mem_alloc)
#> # A tibble: 2 × 3
#>   expression           median mem_alloc
#>   <bch:expr>         <bch:tm> <bch:byt>
#> 1 map_is_unknown_val   86.1µs     201KB
#> 2 is_atomic              41ns        0B

I added this early return and opted not to make any other changes, though folks with a better understanding of the situations where this ends up used might have a better sense for whether we can trim out any of the remaining body of check_for_unknowns(). :)

github-actions[bot] commented 10 months ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.