Skip to content

Performance of [[ #1353

Open
Open
@mgirlich

Description

@mgirlich

While working on rectangling tool for recursive data frames (see tidyverse/tidyr#1386) I noticed that tibble::[[ actually had quite a performance impact. Do you see a chance of improving the performance? Or maybe a low level version for assignment?

f <- function(x, n = 10e3) {
  for (i in seq(n)) {
    x[["x"]] <- 1L
  }
}

t <- tibble::tibble(x = 1L)
df <- data.frame(x = 1L)
l <- list(x = 1L)

bench::mark(
  tibble = f(t),
  dataframe = f(df),
  list = f(l)
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 3 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 tibble     523.22ms 523.22ms      1.91   211.5KB     15.3
#> 2 dataframe   78.31ms  80.04ms     12.0     80.9KB     18.0
#> 3 list         1.35ms   1.52ms    560.          0B     31.9

Created on 2022-08-25 with reprex v2.0.2

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