Skip to content

vec_init() is much slower than vec_slice() #1423

@DavisVaughan

Description

@DavisVaughan

Due to the R level calls to vec_cast() and vec_assert(). We could definitely move these checks down to C

library(vctrs)

x <- rep(list(1), times = 10000)

bench::mark(
  lapply(x, vec_init, n = 1L),
  lapply(x, vec_slice, i = NA_integer_),
  lapply(x, function(xx) {
    .Call(vctrs:::vctrs_init, xx, 1L)
  })
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 3 x 6
#>   expression                                                         min  median
#>   <bch:expr>                                                    <bch:tm> <bch:t>
#> 1 lapply(x, vec_init, n = 1L)                                    71.01ms 76.23ms
#> 2 lapply(x, vec_slice, i = NA_integer_)                           8.64ms 10.28ms
#> 3 lapply(x, function(xx) { .Call(vctrs:::vctrs_init, xx, 1L) })   8.57ms  9.46ms
#> # … with 3 more variables: itr/sec <dbl>, mem_alloc <bch:byt>, gc/sec <dbl>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions