New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of enframe #353

Closed
hadley opened this Issue Jan 4, 2018 · 1 comment

Comments

Projects
2 participants
@hadley
Member

hadley commented Jan 4, 2018

By using lower level constructor.

library(tibble)
options(digits = 3)

enframe2 <- function(x, name = "name", value = "value") {
  if (rlang::is_null(names(x))) {
    l <- list(seq_along(x), x)
  } else {
    l <- list(names(x), unname(x))
  }
  names(l) <- c(name, value)
  new_tibble(l)
}

x <- setNames(letters, letters)

microbenchmark::microbenchmark(
  enframe(x),
  enframe2(x)
)
#> Unit: microseconds
#>         expr    min     lq mean median     uq   max neval cld
#>   enframe(x) 1066.2 1116.9 1792 1185.7 1270.3 39110   100   b
#>  enframe2(x)   77.9   85.2  157   89.9   97.2  4283   100  a

(This is with dev rlang so I'm a little surprised that the speed difference is still so huge - it's probably worth a little profiling of data_frame)

@krlmlr

This comment has been minimized.

Member

krlmlr commented Jan 4, 2018

Will add this to #348.

@krlmlr krlmlr closed this in bd6af96 Jan 15, 2018

krlmlr added a commit that referenced this issue Jan 15, 2018

Merge pull request #348 from tidyverse/f-fast
- Faster construction and subsetting for tibbles (#353).

@krlmlr krlmlr added this to Done in krlmlr via automation Jan 15, 2018

krlmlr added a commit that referenced this issue Jan 20, 2018

Merge tag 'v1.4.1.9001'
- `enframe(NULL)` now returns the same as `enframe(logical())` (#352).
- `tbl[1, , drop = TRUE]` now behaves identically to data frames (#367).
- The `tibble.width` option is honored again (#369).
- Faster printing of very wide tibbles (#360).
- Update vignette to match changes in 1.4.1 (#368, @bgreenwell).
- Don't rely on `ncol()` for `glimpse()`, only query `nrow()` and `head()`.
- Return input for zero-column data frames.
- Add test for `glimpse()` with unknown rows (#366, @kevinykuo).
- Faster construction and subsetting for tibbles (#353).
- `tribble()` now ignores trailing commas (#342, @LaDilettante).
- Fix error message when accessing columns using a logical index vector (#337, @mundl).

krlmlr added a commit that referenced this issue Jan 23, 2018

Merge tag 'v1.4.2'
Bug fixes
---------

- Fix OS X builds.
- The `tibble.width` option is honored again (#369).
- `tbl[1, , drop = TRUE]` now behaves identically to data frames (#367).
- Fix error message when accessing columns using a logical index vector (#337, @mundl).
- `glimpse()` returns its input for zero-column data frames.

Features
--------

- `enframe(NULL)` now returns the same as `enframe(logical())` (#352).
- `tribble()` now ignores trailing commas (#342, @LaDilettante).
- Updated vignettes and website documentation.

Performance
-----------

- Faster printing of very wide tibbles (#360).
- Faster construction and subsetting for tibbles (#353).
- Only call `nrow()` and `head()` in `glimpse()`, not `ncol()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment