Skip to content

return early when possible in spec checking #931

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 17, 2023
Merged

Conversation

simonpcouch
Copy link
Contributor

We've managed to cut down on calls to check_spec_mode_engine_val() in many places, though in most cases we're dropped into there we can still return early. It's hard to troubleshoot exactly what went wrong with misspecified specifications, but since the parsnip model environment is our ground truth for when a specification is well-defined, we should first look to it to see if we can skip the remaining checks. For quick fits like stats::lm() on a small dataset, this makes parsnip about twice as fast!😮

With main dev:

library(parsnip)

bench::mark(
  total = fit(linear_reg(), mpg ~ ., mtcars),
  iterations = 25
)
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 total        7.65ms   8.04ms      120.    7.19MB     67.6

With this PR:

library(parsnip)

bench::mark(
  total = fit(linear_reg(), mpg ~ ., mtcars),
  iterations = 25
)
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 total         3.7ms   3.87ms      255.    7.12MB     48.5

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

There are additional tests for this infrastructure in extratests—they are fine. :)

@topepo topepo merged commit 2f886a3 into main Mar 17, 2023
@topepo topepo deleted the check-early-return branch March 17, 2023 20:48
@github-actions
Copy link

github-actions bot commented Apr 1, 2023

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 Apr 1, 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