Skip to content

Conversation

simonpcouch
Copy link
Contributor

Noticed this when reviewing #1167 but it's unrelated to that PR. If we do the "cheap" side of the && first, we can cut down on the overhead of "not converting to sparse when we don't want to." :)

Before this PR:

d <- data.frame(sparse = "no")
lr <- linear_reg()
bench::mark(
  to_sparse_data_frame(d, lr)
)
#> # A tibble: 1 × 13
#>   expression              min median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result
#>   <bch:expr>           <bch:> <bch:>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list>
#> 1 to_sparse_data_fram… 26.9µs 28.5µs    33538.        0B     16.8  9995     5      298ms <df>  
# ℹ 3 more variables: memory <list>, time <list>, gc <list>

Now:

#> # A tibble: 1 × 13
#>   expression              min median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result
#>   <bch:expr>           <bch:> <bch:>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list>
#> 1 to_sparse_data_fram… 16.1µs 17.5µs    54942.        0B     16.5  9997     3      182ms <df> 

We're talking about 1.5% of the total time in fit(lr, mpg ~ ., mtcars) vs 2.5%, but seems like a simple enough change to be worth it!

@EmilHvitfeldt
Copy link
Member

nice find!

@EmilHvitfeldt EmilHvitfeldt merged commit bc27e2b into main Sep 5, 2024
10 checks passed
@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 Sep 20, 2024
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