Skip to content

Deprecation in map_chr() is quite slow #1089

@mgirlich

Description

@mgirlich

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviormap 🗺️

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions