Skip to content

write out unneeded nest() call #640

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

Merged
merged 1 commit into from
Mar 16, 2023
Merged

write out unneeded nest() call #640

merged 1 commit into from
Mar 16, 2023

Conversation

simonpcouch
Copy link
Contributor

We call tidyr::nest() on grid information for each resample (or, depending on parallel_over, each resample vs model vs preprocessor combination). Taken together, this nesting takes up a good amount of time, especially so for fits to many resamples and quickly-running model fits.

In this case, writing that nest() call out saves us something like 8% of evaluation time. With main dev:

library(tidymodels)

bench::mark(
  res = fit_resamples(linear_reg(), mpg ~ ., bootstraps(mtcars, 100))
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 res           3.14s    3.14s     0.319    46.6MB     8.60

With this PR:

#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 res           2.89s    2.89s     0.346    46.4MB     8.66

Created on 2023-03-15 with reprex v2.0.2

Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@simonpcouch simonpcouch merged commit 92b9e47 into main Mar 16, 2023
@simonpcouch simonpcouch deleted the nest branch March 16, 2023 12:51
@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants