Skip to content

performance loss in as_list_of() due to list2() #1170

@mgirlich

Description

@mgirlich

Both as_list_of.list() and as_list_of.vctrs_list_of() call list_of(!!!x, .ptype = .ptype) which directly collects the input again via list2(). As profvis shows this roundtrip doubles to triples the time required

image

vctrs:::as_list_of.list <- function (x, ..., .ptype = NULL) {
    list_of(!!!x, .ptype = .ptype)
}

vctrs:::list_of <- function (..., .ptype = NULL) {
    args <- list2(...)
    ptype <- vec_ptype_common(!!!args, .ptype = .ptype)
    if (is.null(ptype)) {
        abort("Could not find common type for elements of `x`.")
    }
    x <- map(args, vec_cast, to = ptype)
    new_list_of(x, ptype)
}

I don't know if r-lib/rlang#937 would help to speed this up but it would be great if one could avoid this performance loss which feels quite unnecessary.

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