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

Use minimal defer() instead of local_bindings() #1093

Merged
merged 3 commits into from
Jul 27, 2023
Merged

Use minimal defer() instead of local_bindings() #1093

merged 3 commits into from
Jul 27, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Jul 27, 2023

Fixes #1089

This seems to eliminate most of the performance problem:

library(purrr)
x <- as.list(letters)

bench::mark(
  map_chr = map_chr(x, function(x) paste0(x, "a")),
  map = map(x, function(x) paste0(x, "a")) |> list_c(ptype = character()),
  map_vec = 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      39.6µs   41.4µs    23769.    3.88MB     35.7
#> 2 map            46µs   47.7µs    20567.   51.27KB     36.2
#> 3 map_vec      52.2µs   53.9µs    18327.      71KB     35.9

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

Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'd also appreciate if @lionel- could take a quick look since he did all the defer() work. @lionel- FYI purrr requires R >= 3.5.0 now so this should be safe on all supported R versions.

@@ -23,10 +23,18 @@ deprecate_to_char <- function(type) {
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly worth a news bullet

@hadley hadley merged commit 1019107 into main Jul 27, 2023
11 checks passed
@hadley hadley deleted the faster-dep-env branch July 27, 2023 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation in map_chr() is quite slow
4 participants