Skip to content

vec_cbind() is very slow with many data frames due to vec_cbind_frame_ptype() dispatch #2077

@DavisVaughan

Description

@DavisVaughan

Surely there is a way we can detect bare data frames and bare tibbles and do some internal fast version of x[0] here that doesn't need to call back to R. For those types, we just need an empty list marked with init_data_frame() with the correct row size. It's still an allocation to make that empty list for each element, but should be much faster.

cbinding many data frames together is admittedly not that common, but this is still pretty bad.

library(vctrs)
library(rlang)
names <- paste0("a", 1:1e6)
x <- lapply(names, \(name) {
  set_names(data_frame(x = 1), name)
})
bench::mark(vec_cbind(!!!x), iterations = 2)

^ This takes upwards of 10-12 seconds, 90% of which is in vec_cbind_frame_ptype().

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions