vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

vec_c(<integer64>)

Open romainfrancois opened this issue 3 years ago • 1 comments

originally from: https://github.com/tidyverse/dplyr/issues/5742

library(dplyr, warn.conflicts = FALSE)
library(vctrs, warn.conflicts = FALSE)

suppressPackageStartupMessages(library(bit64))

df <- tibble(x = 1, x64 = integer64(1), xstr = "1", y = sample(10000, 1000000, replace = T)) %>% group_by(y)

first_i64 <- group_map(df, ~.x$x64[1])
first_int <- group_map(df, ~.x$x[1])

type_common <- function(x) vec_ptype_common(!!!x)
vec_c2 <- function(x) vec_c(!!!x)

bench::mark(
  type_common(first_int),
  vec_c2(first_int),
  type_common(first_i64),
  vec_c2(first_i64),
  
  check = FALSE
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 4 x 6
#>   expression                  min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>             <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 type_common(first_int) 479.41µs 491.81µs  1878.       2.38KB      0  
#> 2 vec_c2(first_int)        2.04ms    2.1ms   465.     195.45KB      0  
#> 3 type_common(first_i64) 581.87ms 581.87ms     1.72   131.07KB     22.3
#> 4 vec_c2(first_i64)         2.04s    2.04s     0.489  764.05MB     12.2

Created on 2021-02-11 by the reprex package (v0.3.0)

romainfrancois avatar Feb 11 '21 12:02 romainfrancois

I think much of the type-common slowdown could be fixed by making vec_ptype() a generic, then by giving integer64 a fast vec_ptype.integer64() method. I drafted a PR to make vec-ptype generic in https://github.com/r-lib/vctrs/pull/1322. It would also help with clock types.

In general, any type we don't natively support is going to be much slower when you are working with >= 1 million individual elements of it

DavisVaughan avatar Feb 11 '21 12:02 DavisVaughan