vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

Fast path for `vec_assign(x, integer())`?

Open mgirlich opened this issue 3 years ago • 0 comments

Similarly to #1400 I think it would make sense to have a fast path for vec_assign(x, integer())

The motivation is also similar: e.g. when using vec_assign() in a coalesce() like fashion vec_assign(x, is.na(x), 1L).

Benchmark

library(rlang)
library(vctrs)

x <- 0L + 1:10e6

bench::mark(
  vec_assign = {vec_assign(x, integer(), integer())},
  check = FALSE
)
#> # A tibble: 1 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 vec_assign    5.1ms   5.53ms      165.    38.2MB     172.

Created on 2021-06-25 by the reprex package (v2.0.0)

mgirlich avatar Jun 25 '21 07:06 mgirlich