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

read_model_info_table() only once #910

Merged
merged 2 commits into from
Mar 9, 2023
Merged

read_model_info_table() only once #910

merged 2 commits into from
Mar 9, 2023

Conversation

simonpcouch
Copy link
Contributor

The read_model_info_table() helper is called 3 times per fit, and is read from file each time.

library(tidymodels)

bt <- bootstraps(mtcars, 100)

bm <- 
  bench::mark(
    total = 
      fit_resamples(linear_reg(), mpg ~ ., bt),
    read_model_info_table = 
      replicate(300, parsnip:::read_model_info_table()),
    check = FALSE
  )
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.

bm
#> # A tibble: 2 × 6
#>   expression                 min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>            <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 total                    5.94s    5.94s     0.168      57MB     8.92
#> 2 read_model_info_table 215.87ms 219.19ms     4.57     25.1MB     3.04

As a percentage of total time, the check takes:

100 * as.numeric(bm$median[2]) / as.numeric(bm$median[1])
#> [1] 3.887301

This PR proposes, instead, assigning the function output directly into the namespace once and then referring to its output from then on.

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

R/aaa_models.R Outdated Show resolved Hide resolved
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.

Great find! 1 suggetion

@simonpcouch simonpcouch merged commit 21fc519 into main Mar 9, 2023
@simonpcouch simonpcouch deleted the model-info-table branch March 9, 2023 13:29
@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 25, 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