Skip to content

vec_rbind() performance regression on R 4.0 with df-cols #1122

Description

@DavisVaughan

Performance regression when rbinding lots of data frames that have df-cols. I'm sure this has to do with making extra copies, but I'm not sure where yet. I'll take a look.

This is with dev vctrs.

R 3.6

library(vctrs)

df_col <- new_data_frame(list(x = 1:2))
df <- new_data_frame(list(y = df_col))

x <- rep_len(list(df), 10000)
y <- rep_len(list(df_col), 10000)

lst_rbind <- function(x) {
  vec_rbind(!!!x)
}

bench::mark(lst_rbind(x))
#> # 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 lst_rbind(x)   37.5ms   37.9ms      26.2     277KB     52.4

bench::mark(lst_rbind(y))
#> # 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 lst_rbind(y)   16.5ms   18.2ms      55.1     274KB     16.5

R 4.0

library(vctrs)

df_col <- new_data_frame(list(x = 1:2))
df <- new_data_frame(list(y = df_col))

x <- rep_len(list(df), 10000)
y <- rep_len(list(df_col), 10000)

lst_rbind <- function(x) {
  vec_rbind(!!!x)
}

bench::mark(lst_rbind(x))
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # 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 lst_rbind(x)    316ms    352ms      2.84     764MB     48.2

bench::mark(lst_rbind(y))
#> # 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 lst_rbind(y)   15.8ms   17.6ms      55.6     274KB     23.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions