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

Remove unneeded arg_match() #1149

Closed
wants to merge 3 commits into from
Closed

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Jun 14, 2020

With UI tests.

Makes vec_as_location2() quite a bit faster, realistically we need to remove that tryCatch() and perhaps rewrite in C to make performance comparable with base.

vctrs main

library(vctrs)
library(magrittr)

bench::mark(
  vec_as_location2("x", 1L, "x", missing = "propagate", arg = "x"),
  iterations = 1000
) %>%
  dplyr::select(-expression)
#> # A tibble: 1 x 5
#>        min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1   78.7µs   88.8µs     9451.     322KB     18.9

Created on 2020-06-14 by the reprex package (v0.3.0)

This PR

library(vctrs)
library(magrittr)

bench::mark(
  vec_as_location2("x", 1L, "x", missing = "propagate", arg = "x"),
  iterations = 10000
) %>%
  dplyr::select(-expression)
#> # A tibble: 1 x 5
#>        min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1   24.8µs   28.1µs    32548.     174KB     16.3

Created on 2020-06-14 by the reprex package (v0.3.0)

@@ -158,16 +158,21 @@ vec_as_location2_result <- function(i,
missing,
negative,
arg) {
allow_missing <- arg_match(missing, c("error", "propagate")) == "propagate"
allow_negative <- arg_match(negative, c("error", "ignore")) == "ignore"
allow_missing <- (missing == "propagate")
Copy link
Member

Choose a reason for hiding this comment

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

This becomes a length > 1 vector so we need to match?

Copy link
Member

Choose a reason for hiding this comment

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

Let's just use arg_match0()? I'm going to focus on rlang and vctrs releases today and tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, once rlang > 0.4.6 is on CRAN we can use that.

@krlmlr
Copy link
Member Author

krlmlr commented Jul 6, 2020

UI tests integrated in #1146.

@krlmlr krlmlr closed this Jul 6, 2020
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.

2 participants