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

Deprecation in map_chr() is quite slow #1089

Closed
mgirlich opened this issue Jul 5, 2023 · 3 comments · Fixed by #1093
Closed

Deprecation in map_chr() is quite slow #1089

mgirlich opened this issue Jul 5, 2023 · 3 comments · Fixed by #1093
Labels
bug an unexpected problem or unintended behavior map 🗺️

Comments

@mgirlich
Copy link
Contributor

mgirlich commented Jul 5, 2023

Setting up the deprecation env takes roughly a third of the time in the following reprex. Using map_vec() is actually faster:

x <- as.list(letters)

for (i in 1:10e3) {
  purrr::map_chr(x, function(x) paste0(x, "a"))
}

bench::mark(
  map_chr = purrr::map_chr(x, function(x) paste0(x, "a")),
  map = purrr::map(x, function(x) paste0(x, "a")) |> 
    purrr::list_c(ptype = character()),
  map_vec = purrr::map_vec(x, function(x) paste0(x, "a"), .ptype = character())
)
#> # A tibble: 3 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 map_chr     181.5µs  190.5µs     4425.    5.77KB     12.4
#> 2 map          89.5µs   96.1µs     9057.    47.1KB     12.6
#> 3 map_vec     100.9µs  106.8µs     8268.   40.55KB     14.5

Created on 2023-07-05 with reprex v2.0.2

image

@hadley hadley added bug an unexpected problem or unintended behavior map 🗺️ labels Jul 26, 2023
@hadley
Copy link
Member

hadley commented Jul 26, 2023

Ugh, that's a bummer.

@DavisVaughan
Copy link
Member

Most of it is probably withr::defer()

The standalone-defer file was improved here:
r-lib/withr#221

But that hasn't made its way to CRAN yet (or to rlang, which uses the standalone file)

And we think the ultimate goal was to move defer() to rlang and rewrite in C, but we haven't had time for that yet either.

@hadley
Copy link
Member

hadley commented Jul 26, 2023

We could just use on.exit() here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior map 🗺️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants